how to set specific version of node as default using n - node.js

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

Related

How to update nodejs version [duplicate]

This question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
I did the following to update my npm:
npm update npm -g
But I have no idea how to update Node.js. Any suggestions? (I'm using Node.js 0.4.1 and want to update to Node.js 0.6.1.)
To upgrade Node you may first want to see which version of Node.js you are currently using:
node --version
Find out which versions of Node.js you may have installed and which one of those you're currently using:
nvm ls
List all versions of Node.js available for installation:
nvm ls-remote
Apparently for Windows the command would be rather like this:
nvm ls available
Assuming you would pick Node.js v8.1.0 for installation you'd type the following to install that version:
nvm install 8.1.0
You are then free to choose between installed versions of Node.js. So if you would need to use an older version like v4.2.0 you would set it as the active version like this:
nvm use 4.2
That should be all.
In 2013 I used the following instructions to upgrade from Node.js version 0.10.6 to 0.10.21 on a Mac, for more recent instructions see above.
Update from 2017: Please mind, Mr. Walsh himself recommended to update Node.js just using nvm instead.
Clear NPM's cache:
sudo npm cache clean -f
Install a little helper called 'n'
sudo npm install -g n
Install latest stable Node.js version
sudo n stable
Alternatively pick a specific version and install like this:
sudo n 0.8.20
For production environments you might want to pay attention to version numbering and be picky about odd/even numbers.
Credits
General procedure: D.Walsh
Stable/unstable versions: P.Teixeira
Use Node Version Manager (NVM)
It's a Bash script that lets you download and manage different versions of node. Full source code is here.
There is a separate project for nvm for Windows: github.com/coreybutler/nvm-windows
Below are the full steps to use NVM for multiple version of node on windows
download nvm-setup.zip extract and install it.
execute command nvm list available from cmd or gitbash or powershell, this will list all available version of node
use command nvm install version e.g. nvm install 12.14.0 to install on the machine
last once installed use nvm use version to use newer version e.g. nvm use 12.14.0
Any OS (including Windows, Mac & Linux)
Updated October 2022
Just go to the official Node.js site (nodejs.org), download and execute the installer program.
It will take care of everything and with a few clicks of 'Next' you'll get the latest Node.js version running on your machine. Since 2020 it's the recommended way to update NodeJS. It's the easiest and least frustrating solution.
Pro tips
NodeJS installation includes NPM (Node package manager).
To check your NPM version use npm version or node --version.
If you prefer CLI, to update NPM use npm install -g npm and then npm install -g node.
For more details, see the docs for install command.
Keep an eye on NodeJS blog - Vulnerabilities so you don't miss important security releases. Keep your NodeJS up-to-date.
Operating systems supported by Node.js:
Windows, Linux, MacOS, IBM AIX.
For Docker users, here's the official Node.js image.
For more information on installing Node.js on a variety of less-common operating systems, see this page (there's even Node for Android!).
Troubleshooting for Windows:
If anyone gets file error 2502/2503 like myself during install, run
the .msi via Administrator command prompt with command msiexec /package [node msi]
If my answer is helpful, don't forget to upvote it
(here is the original answer by Anmol Saraf, upvote it too)
If you have Homebrew installed (only for macOS):
$ brew upgrade node
2021: Just go to nodejs.org and use the latest installer.
That's it folks. It used to be more complex and people used different kinds of packages and strategies to manage it. But things have changed for the better.
Works for all platforms (Windows, Mac & Linux).
First update npm,
npm install -g npm stable
Then update node,
npm install -g node or npm install -g n
check after version installation,
node --version or node -v
On Windows you can use Chocolatey to install and update Node.js (and lots of other packages).
Install Node
cinst nodejs.install
Update Node
cup nodejs.install
Note: You will need to install Chocolatey before you can use cinst and cup.
To upgrade node to the latest version or to a specific version you can do the following:
sudo npm install n -g
sudo n 0.10.18 // This will give you the specific version
For the latest stable version:
sudo n stable
For the latest LTS version(Tested on Mac)
sudo n lts
To control your version of Node.js, you can try n. I found it very straightforward and useful.
n is a Node.js binary management, no subshells, no profile setup, no convoluted API, just simple.
npm install -g n
n 0.6.19 will install Node.js v0.6.19.
Short answer:
Go to this page: Download | Node.js
Download the installer for your platform, then install it.
I had the same problem, when I saw that my Node.js installation is outdated.
These few lines will handle everything (for Ubuntu):
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
After this node -v will return you the latest available version.
On CentOS 7 you can do the following:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/5.4.1/bin/node /usr/bin/node
node –v (Should show updated version now)
npm rebuild node-sass (Optional: if you use this)
Note: The symlink is required to link your node binary with the latest Node.js installed binary file.
For OS X, I had v5.4.1 and needed the latest version 6 so I went to the Node.js homepage and clicked on one of the links below:
I then followed the installer and then I magically had the latest version of Node.js and npm.
For macOS in 2018+
(as ALL of the solutions above are failing for me):
Simply go to the official nodejs site, download the official nodejs package and install it by double clicking. It's the most simple, safe and always-working thing you can do.
You may use nvm.
Check what is the latest version at http://nodejs.org/ (e.g. v0.10.26)
Run nvm install v0.10.26
Done.
You can choose which version to run:
nvm ls list the available versions and tells you which version you are using now.
nvm use VERSION change the current node to the requested version.
nvm alias default VERSION set the default version. The next time you source nvm.sh, this will be the version loaded (note that it doesn't change the version in use right now, run nvm use for that).
Some Linux distributions such as Arch Linux have Node.js in their package repositories. On such systems it is better to use a standard package update procedure, such as pacman -Suy or analogous apt-get or yum commands.
As of now (Nov 2016) EPEL7 offers a pretty recent version of Node.js (6.9.1 which is an up-to-date LTS version offered on the Node.js home page). So on CentOS 7 and derivatives you can just add EPEL repository by yum install epel-release and yum install nodejs.
CentOS 6/EPEL6 has 0.10.x which isn't supported upstream since Oct 2016.
Today I ran on a Windows Git Bash:
$ npm i node -g
and got the following output:
> node#10.6.0 preinstall C:\Users\X\AppData\Roaming\npm\node_modules\node
> node installArchSpecificPackage
+ node-win-x64#10.6.0
added 1 package and audited 1 package in 23.368s
found 0 vulnerabilities
C:\Users\X\AppData\Roaming\npm\node -> C:\Users\X\AppData\Roaming\npm\node_modules\node\bin\node
+ node#10.6.0
added 2 packages from 1 contributor in 26.089s
Read more about it at https://www.npmjs.com/package/node.
The easy way to update node and npm :
npm install -g npm#latest
download the latest version of node js and update /install
$ npm install -g npm stable
worked for me to update npm
Install nvm(cURL)
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash
OR with Wget
$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
Display list of installed versions
$ nvm ls
Display list of versions that are available to install
$ nvm ls-remote
Install your preferred version
$ nvm install v7.5.0
Set this version as the default
$ nvm alias default v7.5.0
For Ubuntu:
sudo apt-get install -y curl
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
sudo apt-get install -y nodejs
Source: https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version
You may use Chocolatey on Windows. It's very easy to use and useful for keeping you updated with other applications too.
Also, you can just simply download the latest version from https://nodejs.org and install it.
According to Nodejs Official Page, you can install&update new node version on windows using Chocolatey or Scoop
Using(Chocolatey):
cinst nodejs
# or for full install with npm
cinst nodejs.install
Using(Scoop):
scoop install nodejs
Also you can download the Windows Installer directly from the nodejs.org web site
As some of you already said, the easiest way is to update Node.js through the Node.js package manager, npm. If you are a Linux (Debian-based in my case) user I would suggest to add these lines to your .bashrc file (in home directory):
function nodejsupdate() {
ARGC=$#
version=latest
if [ $ARGC != 0 ]; then
version=$1
fi
sudo npm cache clean -f
sudo npm install -g n
sudo n $version
}
Restart your terminal after saving and write nodejsupdate to update to the latest version of Node.js or nodejsupdate v6.0.0 (for example) to update to a specific version of Node.js.
BONUS: Update npm (add these lines to .bashrc)
function npmupdate() {
sudo npm i npm -g
}
After restarting the terminal write npmupdate to update your node package manager to the latest version.
Now you can update Node.js and npm through your terminal (easier).
In windows download the node executable file from the website and install it. this worked for me.
All you need to version update of Node.js:
$ brew install node
If you don't have Homebrew; please go http://brew.sh/.
Just install the new version over the current folder. I upgraded mine from v4.x to v6.10 on Windows.
npm clean cache - you forget to clean ur cache
npm update -g
This works on mine Windows, I hope it will also work for you :D
If you want to update Node.js, just try
npm update
from your Windows cmd prompt.
Else if you want to update any specific package try
npm update <package_name>
Example:
npm update phonegap
open cmd and type
npm i -g npm

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 check and change the Nodejs version on Ubuntu?

I am using Ubuntu Linux.
How can I check current nodejs version? I guess, I have 6 version, but I am not sure.
And is there way to change it, because I need 4 version. Can some one give step by step commands?
Open up the terminal and type node -v
To change your node version, I'd recommend installing nvm. Once installed, to switch versions it's as simple as
nvm use <version>
You can check your current NodeJS version by using command node -v.
And changing your version can be done by using node version manager.
The easiest way to do that is by running this $ npm install -g n now you can change your current NodeJS version using n (version)
e.g. n 4.0.0.
node -v
npm install -g n
n 4.0.0
You can check your version by using this code (node -v) in linux terminal and If you want to upgrade it to stable version you can use following codes one by one.
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Just type npm version in your command line and it will display all the version details about node, npm, v8 engine etc.
To change your node version, I'd recommend installing nvm. Once installed, switch versions follow the instruction below;
nvm use <any specified version you prefer "example v16.0.0">
Example:
nvm alias default 16
This will enforce as the current default version.

Cannot upgrade Node.js using n

I'm trying to update Node.js on Ubuntu serever 14.04 using n.
n upgrades but the version is still the same:
root#0e2dbaa3db85:/home# node -v
v0.10.25
root#0e2dbaa3db85:/home# n 0.10.33
install : node-v0.10.33
mkdir : /usr/local/n/versions/node/0.10.33
fetch : https://nodejs.org/dist/v0.10.33/node-v0.10.33-linux-x64.tar.gz
installed : v0.10.33
root#0e2dbaa3db85:/home# node -v
v0.10.25
Do I have to tell n which version to use as default?
I've tried n latest, it installs 0.12.0 but node -v outputs 0.10.25 again.
What should I do?
On occasion the n package won't install the links for node, and the selection won't allow you to select any version installed by n.
When that happens, you need to install an "n" version of node so the selector will allow you to choose.
Here is what I had to do.
Use n to install a node version.
# n stable
install : node-v5.10.1
mkdir : /usr/local/n/versions/node/5.10.1
fetch : https://nodejs.org/dist/v5.10.1/node-v5.10.1-linux-x64.tar.gz
######################################################################## 100.0%
installed : v0.10.42
Select the node version from the install directory
In this case it is located at:
/usr/local/n/versions/node/5.10.1/bin/node
Replace existing node link with new node version
cd /bin
mv node node_old
ln -s /usr/local/n/versions/node/5.10.1/bin/node
At this point node should work, and n should allow you to select version.
Resolved by nvm.
I faced the same issue with you. I could not change node version with n because I installed nvm and used nvm to manage node versions before.
I resolved the issue by execute nvm command. For example: nvm install 11.8.0 then check node version node -v. Tada it works.
n 0.10.33 will install that version of node, but you still haven't selected it. After installing, simply execute n and pick the version you want to use.
n latest will install or activate the latest version of node. Run it twice to use node 0.12.0
Documentation.
I faced same issue, where I select a different version or even download a new version with n and it still shows the initial installation before I started using n. This worked for me:
Unlink
sudo unlink /usr/bin/node
Run n again to choose the node version.
After this two steps it worked
From what I can read from the n readme, you need to call n <version> to install, and then run n with no arguments, so a version picker will be shown:
Type n to prompt selection of an installed node. Use the up / down arrow to navigate, and press enter or the right arrow to select, or ^C to cancel:
(...)
Commands:
n <version> Install node <version>
However, if you run n latest, it will install or activate the latest version:
n latest Install or activate the latest node release
Try to set the simbolic link to node to the npm global folder.
sudo unlink /usr/bin/node
sudo ln -rs PATHTO/.npm-global/node/bin/nodee node
in my case, my path to npm-global dir was on my home. So the full path was /home/rafael/.npm-global/node/bin/node
After this, check if is allrigth:
node -v //return current node version
n stable //install the stable current version
node -v //will return the new version installed
n 8 //install the version 8 for test
node -v //will return the 8 version
Enjoy

Resources