Node upgrade doesn't work in my case: - node.js

I want to upgrade node to the latest stable version ( 6.9.5 ) but it doesn't work:
# node -v
v0.10.37
# sudo npm cache clean -f
npm WARN using --force I sure hope you know what you are doing.
# sudo npm install -g n
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
/usr/local/lib
└── n#2.1.4
# sudo n 6.9.5
install : node-v6.9.5
mkdir : /usr/local/n/versions/node/6.9.5
fetch : https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.gz
######################################################################## 100,0%
installed : v6.9.5
# node -v
v0.10.37

You need to specify to use the version of node you just installed
n use 6.9.5 script.js
You can list node versions installed with n using
n
If you want to set your default node version you will need to change the path to your node binary, get it by executing:
n bin 6.9.5
In Linux, MacOS and BSD, in your .bashrc/.zshrc you should modify line:
export PATH=$PATH:/usr/local/nodejs/bin
to refer to the path you got earlier.
On Windows set it similarly in the PATH variable in your system environment variables.
Referencing docs.

Related

How to upgrade node to specific version in macOS Mojave, and update the active path for node?

I want to upgrade node to 12.10.0 and npm to 6.11.3, currently I am working on macOS Mojave version 10.14.5
I am using these commands to upgrade the node version to 12.10.0::
sudo npm cache clean -f (force) clear you npm cache
sudo npm install -g n install n (this might take a while)
sudo n 12.10.0 upgrade to the specific version
After running the last command it gives me an output like::
installing : node-v12.10.0
mkdir : /usr/local/n/versions/node/12.10.0
fetch : https://nodejs.org/dist/v12.10.0/node-v12.10.0-darwin-x64.tar.gz
installed : v12.10.0 to /usr/local/bin/node
active : v10.16.3 at /usr/local/opt/node#10/bin/node
When I am checking for node version node -v it still shows me old version 10.16.3
I have tried to add node path, but still, it gives me the same output.
I have used command sudo nano /etc/path and then added /usr/local/bin/node path to it.
Please suggest me how can I upgrade node to 12.10.0 and npm to 6.11.3 version?
Install nvm following below tutorial :
Install nvm with homebrew
As stated in the link above,
Start by :
brew update
brew install nvm
mkdir ~/.nvm
nano ~/.bash_profile
In your .bash_profile file (you may be using an other file, according to your shell), add the following :
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
Back to your shell, activate nvm and check it (if you have other shells opened and you want to keep them, do the same) :
source ~/.bash_profile
echo $NVM_DIR
Then with the help nvm install any node version(example v12.14.1) you want :
nvm install v12.14.1
nvm use v12.14.1
to switch to 12.14.1 version.
Step 1: Clean npm cache
sudo npm cache clean -f
Step 2: Install node helper (n) globally using the following command.
sudo npm install -g n
Once node helper is installed. You can either get a specific version like I needed 16.14.1 then you can perform.
sudo n 16.14.1
OR You can get the latest stable version using
sudo n stable
Then you can confirm the version installed
node --version
install n (npm module) npm install -g n and run sudo n latest or sudo n <version>
An alternate way to upgrade w/o using brew -
Go to nodejs releases page. The table on this page list the various node release available for download.
Click on the downloads link for the version you need. This will take us to another page to download the node version depending on the OS you are using. For mac, we can download the .pkg format.
After the package is downloaded, we can run it by clicking the downloaded file and hitting 'Next' till we complete.

I cannot switch node.js version

I am trying to switch my node.js version.
What I did is:
sudo npm cache clean -f
sudo npm install -g n
sudo n 10.10.0
But I check my current version after I did it by using
node -v
It always shows
v6.14.3
I am not sure if I do anything wrong. Any suggestion please?
As stated by Intervalia, try using using NVM (node version manager)
With nvm, you can very easily do things like:
nvm install 10.10.0 and it will download that version of node. And then do nvm use 10.10.0 and then doing node -v will return 10.10.0.
Here is what happens when I run nvm list

how to set specific version of node as default using n

I've installed node using the npm by below commands.
sudo npm cache clean -f
sudo npm install -g n
sudo n 8
sudo n 8 installed node 8 .
$ sudo n 8
install : node-v8.11.3
mkdir : /usr/local/n/versions/node/8.11.3
fetch : https://nodejs.org/dist/v8.11.3/node-v8.11.3-darwin-x64.tar.gz
######################################################################## 100.0%
installed : v6.13.1
but didn't set it as default
$ node -v
v6.13.1
How can I set node version 8 as default node version.
You still need to activate the installed version, installing doesn't automatically switch to that version. Type n after doing the install and select the version you want. From that point forward, it will be the node version your system uses. You may need to use sudo n if you run into permission issues.
Try to use NVM, you can have multiple versions of nodejs and it's pretty easy to manage.
https://github.com/creationix/nvm
For my case, i've deleted node package that was installed with system package manager (yum).
In my case, I couldn't change the node version because I installed node through brew, and was then trying to change the version through n (another node version manager, similar to nvm).
All I had to do was:
brew uninstall node
After this, I just had to run:
sudo n 18.14.1

Install nodejs 4.2.0 or above version

I have installed node and npm using following command in my Ubuntu machine:
sudo apt-get install nodejs npm
On checking version of installed, I could see following:
$ node -v && npm -v
v0.10.25
1.3.10
But I want nodejs version to be 4.2.0 or above. I am trying to install VSO Linux agent for a project. On executing node agent/vsoagent, I get error that node version should be 4.2.0 or above.
How do I install it and also make sure that the already installed ones are removed with node -v && npm -v gives me new version number?
Thanks
You already have npm, so you can use n manager to install any version you want (4.4.4 for ex): maybe you should use sudo for global install:
npm install -g n
n 4.4.4
Or
n latest
After that you can just run n to select version that you prefer. I use latest LTS and latest 6.x side-by-side and switching them anytime i want.

Cannot upgrade Node version with the common commands

I have trouble upgrading Node.js.
Currently, I have node --version "v0.8.18" and I would like to upgrade to the latest "v0.10.20". So I followed some answers that does not include NVM, since I want to know how to do it from scratch. However, after trying, I still get node --version "v0.8.18".
I am on an Ubuntu 11.04 machine, on my home directory.
Specifically I did:
Try 1:
alice#simba:~$ node --version
v0.8.18
alice#simba:~$ sudo n stable
sudo: n: command not found
alice#simba:~$ sudo npm install n -g
npm http GET https://registry.npmjs.org/n
npm http 200 https://registry.npmjs.org/n
npm http GET https://registry.npmjs.org/n/-/n-1.1.0.tgz
npm http 200 https://registry.npmjs.org/n/-/n-1.1.0.tgz
/usr/bin/n -> /usr/lib/node_modules/n/bin/n
n#1.1.0 /usr/lib/node_modules/n
alice#simba:~$ sudo n stable
install : 0.10.20
mkdir : /usr/local/n/versions/0.10.20
fetch : http://nodejs.org/dist/v0.10.20/node-v0.10.20-linux-x64.tar.gz
...
...#############/usr/bin/node
installed : v0.10.20
alice#simba:~$ node --version
v0.8.18
Try again:
alice#simba:~$ npm cache clean -f
alice#simba:~$ sudo npm install n -g
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
n#1.1.0 /usr/local/lib/node_modules/n
alice#simba:~$ n stable
/usr/local/bin/node
alice#simba:~$ sudo n stable
/usr/local/bin/node
alice#simba:~$ node --version
v0.8.18
I use nvm myself, but something I've bumped up against in the past is that installing a version and selecting a version as active are different operations.
It may be that your new version is installed but not currently the default. Try:
n use 0.10.20

Resources