Upgrade NodeJS leaves me with two versions - node.js

I attempted an upgrade of Node using brew, but after the upgrade I am left with two versions. How can I get rid of the old one?
When I run brew upgrade node It tells me that 0.12.7 is already installed.
However if I run node -v
I get the version 0.10.26. It appears that I now have two versions installed.
How can I remove the oldest version?

One option is to delete your node binary folder which will contain those two files:
sudo rm -rf /usr/local/lib/node
And then run install again:
brew install node
Be sure to backup your folder PRIOR to doing this in the case it freaks out.
Also - from personal experience, homebrew creates more problems that it solves. Just use the Node.js install script on their website.

Related

Updating to stable version of nodejs with n

this is my first time trying to update the nodejs version of a unix server. I want to use it to create a react app, and facing the following:
>npx create-react-app test
You are running Node 8.11.3.
Create React App requires Node 10 or higher.
Please update your version of Node.
So I have tried to update the version with the following commands:
>sudo npm cache clean -f
>sudo npm install -g n
>sudo n stable
installed : v14.15.4 to /usr/local/bin/node
active : v8.11.3 at /bin/node
However it seems that didn't upgrade the version, it installed a different version in a different path.
I am not sure if it is possible just to upgrade the version that is already active, I prefer not to do a workaround and just upgrade it directly.
As complementary information if I run n doctor I see the following:
>n doctor
Checking n install destination is in PATH...
'/usr/local/bin' is not in PATH
As I said previously, what I am looking for is a safe way to update the version already installed to be able to use create-react-app, being able to rollback to previous version easily if something doesn't work, I understand that the way is using n.
Thanks in advance.
I suggest you add /usr/local/bin to the start of your PATH (so it comes before /bin).
I do not recommend you try and overwrite /bin/node using n. Something else installed /bin/node in a system directory, and overwriting it using n could leave things in a mixed and confused state. n installs to /usr/local by default, but you can set N_PREFIX to install to your home folder, for example.
To avoid confusion with having two versions of node installed, you may wish to uninstall the /bin version, likely installed by your platform package manager.
Tip: Changing where node and npm are installed is likely to change where your global npm packages are installed. I suggest you list what you have installed now in case you want to reinstall then in the "new" location. npm list -g --depth=0

How to uninstall n and all node versions installed by n

I have installed some Node.js versions with the tool n. I have uninstalled all Node.js versions using:
sudo n prune
except the current (activated) version. If I try to unsinstall the current version:
sudo n rm 6.10.2
I get the following error.:
Error: cannot remove currently active version (node/6.10.2).
I can not figure out, how to set the systems (Arch Linux) default Node.js version, which is already installed and was used to install n.
If uninstall n using:
sudo npm uninstall -g n
it leaves the current version on my computer.
ls /usr/local/n/versions/node/
6.10.2/
Do I need to manually delete the folder: /usr/local/n/? Or, is there an option in n to uninstall it and all the Node.js versions installed by n, so that I get the setting before I installed n?
You need to manually remove Node versions installed by n and set the correct Node system version.
sudo n prune
sudo npm uninstall -g n
sudo rm -r /usr/local/n
sudo rm /usr/local/bin/node
See the following issues for n on GitHub:
Cant uninstall n and node #327
Simple command to switch back to the system installation of Node #486
There have been some changes in n, so I'll provide an updated and longer answer.
First some context. n installs by default to /usr/local. If that is also the location of the "system" install of node and npm then it is overwritten. The cache of previously downloaded versions is kept in /usr/local/n.
Removing cached node versions downloaded by n:
n prune removes all but the version matching the active version of node
since n v3.0.0, deleting the active version is allowed using n rm <version>
(but just manually deleting /usr/local/n is easy and removes the top folder too!)
Removing installed node and npm and npx et al:
since n v4.1.0, there is n uninstall. (You will need to reinstall the system node and npm to keep using them if they were installed to same location and overwritten.)
Uninstalling n itself: if you installed it with npm install n then you uninstall it with npm uninstall n. This does not affect the cached versions of node or the installed version of node, just n. (And there is a small catch-22 if just deleted npm by running n uninstall!)
I'm on mac OSX, so I'm not sure if this is relevant to your use case or not, but it may help.
It looks like n may run into issues if you remove the current version, so I suggest that you delete the folder: /usr/local/n/
Then try to uninstall 'n'. In my case, running npm uninstall -g n did not remove n. Instead, I needed to find the current installation of n by running: which n, then removing that folder from my system.
Then, I would suggest that you use NVM instead.
I've found that it's the easiest and most reliable solution that I've found to date.
More specifically, to address your question about how to access the system installation of node, I don't know what OS you are running, but I don't know that there is a system node version.
Typically, you have to manually install node. If there were a system node version, I would expect that it would become outdated very quickly, considering node, and other tools, typically iterate through changes fairly quickly.
I hope this works for you.
Run n-uninstall to uninstall n as well as the Node.js versions that were installed with it.
n-uninstall -y skips the confirmation prompt - use with caution.

Updating node and npm using Homebrew

I want to upgrade npm but I need Node version >0.10.32
Typing $ brew upgrade node I get:
Error: node 7.2.1 already installed
but with $ node -v I get:
v0.10.24
Why are there two version formats and how can I get node updated to the required version?
I need
You have two different versions of Node installed in different paths.
The one in the directory closer to the front of your $PATH environment variable is 0.10.24.
The one installed by brew is 7.2.1.
If you want to use the brew managed one, then the easiest thing to do is to uninstall the other version.
Alternatively, use the full path to the brew managed one.

Unable to remove NodeJS

It says that node is installed in my /home/raheel/.nvm/v0.10.40/bin/node.
But it does not remove node with apt-get remove node.
I exactly don't remember how did i install it as i was following a tutorial.
Thanks
nvm stores copies of node in a different place than the copy that your package manager installs. Also, it should be noted that the node package in Debian/Ubuntu is not node.js, but instead an amateur radio program (the actual package name is nodejs/nodejs-legacy).
So to remove nvm's copy of node, you could do nvm uninstall 0.10.40 to uninstall that particular version or you can do nvm deactivate to remove nvm's node binaries from your $PATH entirely.

Node install error

Im trying to install node + npm using brew and keep getting the following:
$brew install node
Warning: node-0.10.33_1 already installed, it's just not linked
Any ideas whats going on and how to fix?
Try brew doctor that should give you some idea of what the problem is. Also, I strongly recommend not installing node directly using brew, but actually installing nvm through (brew install nvm)
nvm is the node version manager, which allows you to install different versions of node, and quickly swap between them.
I have the same problem.
but I try lots method (e.g. nvm, uninstall, brew doctor, blabla...), and decide use http://nodejs.org/ pkg instead.
it would install perfectly without homebrew.
but if you are so likely use homebrew, I have no idea about this.
I had this problem as well. It was due to part of a leftover installation from running and using the pkg installer from nodejs.org. Simply:
brew uninstall node
rm -rf /usr/local/include/node
brew install node
And you're good to go. You could probably get away with skipping the uninstall and just performing a brew link node, but I didn't try that.

Resources