How can I update my nodeJS to the latest version?
Emily Wong
I have installed nodeJS on Ubuntu with following code
sudo apt-get install nodejsSince I am a new user for ubuntu I also ran this code too
sudo apt-get install npmNow when I type
nodejs --versionIt shows
v0.6.19I checked and saw latest nodeJS version is 0.10.26
How can I update my version of nodeJS to 0.10.26?
I tried with
sudo apt-get install <packagename> sudo apt-get install --only-upgrade <packagename>but no luck.
115 Answers
Use n module from npm in order to upgrade node
sudo npm cache clean -f
sudo npm install -g n
sudo n stableTo upgrade to latest version (and not current stable) version, you can use
sudo n latestFix PATH:
sudo apt-get install --reinstall nodejs-legacy # fix /usr/bin/nodeTo undo:
sudo n rm 6.0.0 # replace number with version of Node that was installed sudo npm uninstall -g n
You may need to restart your terminal to see the updated node version.
Found in David Walsh blog
41Complete installation instructions have since been uploaded here by Nodesource. It is copied below for your reference. Instructions are the same for updating to the latest version.
If you don't like curl ... | sudo bash - then you can follow the manual instructions, which tells you how to add the Node.js repository to /etc/apt/sources.list.d/ yourself.
NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 6.x on older distros
Node.js Current:
# Using Ubuntu
curl -fsSL | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -fsSL | bash -
apt-get install -y nodejsNode.js v13.x:
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejsNode.js v12.x:
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejsNode.js v11.x:
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejsNode.js v10.x:
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejsNode.js v9.x:
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejsNode.js v8.x:
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejsNode.js v7.x:
NOTE: Debian Wheezy and Ubuntu Precise packages are NOT available for this release. Please reference running Node.js >= 4.x on older distros
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejsNode.js v6.x:
NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 4.x on older distros.
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejsNode.js v5.x:
NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 4.x on older distros.
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejsNode.js v4.x:
NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 4.x on older distros.
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejsNode.js v0.12:
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejsNode.js v0.10:
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejsio.js v3.x:
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y iojs
# Using Debian, as root
curl -sL | bash -
apt-get install -y iojsio.js v2.x:
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y iojs
# Using Debian, as root
curl -sL | bash -
apt-get install -y iojsio.js v1.x:
Note: this branch of io.js is not actively maintained and is not recommended for production use.
# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y iojs
# Using Debian, as root
curl -sL | bash -
apt-get install -y iojs 18 I also recommend using nvm instead, and also removing the already installed version to avoid conflicts in the terminal
sudo apt purge nodejs npmthen install nvm and use it
Video Explanation
curl -o- | bashnvm install nodeshould download and install the latest version of node.
To update node later on just do
nvm install node
nvm alias default node 8 This PPA is out of date and not maintained anymore; you should consider other answers instead of this one.
You can install the latest version from PPA:
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs 4 I use NVM to handle my Node versions. Very simple to set up and easy to use.
curl -o- | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvmTo install NVM globally instead, use the following curl command instead of the one above (and presumably don't use the second command but do use the third one)
curl -o- | NVM_DIR=/usr/local/nvm bashThen use nvm install stable (or insert a version number instead of stable) to get the latest/a specific version of Node. Use nvm use stable (or a specific version number) to use that Node version. Use nvm ls to see what Node versions you have installed and nvm uninstall stable(or a specific version number) to remove a specific version of Node.
Note
If you are struggling with updating npm to the latest stable version because you are stuck at a specific version of npm and every time you update it that doesn't work then you can use this method to update npm as well. As soon as you install the latest stable version of node, npm will automatically be updated to its latest stable version.
NVM (Node Version manager) with --lts
NVM was mentioned at: but here goes a more complete usage example, including the sane --lts version, which installs the latest Long Term Support version of Node, which is likely the one you want if you don't have more specific requirement.
Install NVM and the latest Node LTS version:
curl | sh
source ~/.nvm/nvm.sh
nvm install --lts
nvm use --lts
npm --versionNow test it out with a dummy package:
npm install --global vaca
vacaSince the sourcing has to be done for every new shell, the install script hacks adds some auto sourcing to the end of your .barshrc. That works, but I prefer to remove the auto-added one and add my own:
f="$HOME/.nvm/nvm.sh"
if [ -r "$f" ]; then . "$f" &>'/dev/null' nvm use --lts &>'/dev/null'
fiAdvantages:
allows you to use multiple versions of Node and without sudo
is analogous to Ruby RVM and Python Virtualenv, widely considered best practice in Ruby and Python communities
downloads a pre-compiled binary where possible, and if not it downloads the source and compiles one for you
We can easily switch node versions with:
nvm install 0.9.0
nvm install 0.9.9
nvm use 0.9.0
node --version
#v0.9.0
nvm use 0.9.9
node --version
#v0.9.9You can then use a git tracked .nvmrc file to indicate the node version required for a given project:
With this setup, you get for example:
which nodegives:
/home/ciro/.nvm/versions/node/v0.9.0/bin/nodeand:
which vacagives:
/home/ciro/.nvm/versions/node/v0.9.0/bin/vacaand if we want to use the globally installed module:
npm link vaca
node -e 'console.log(require.resolve("vaca"))'gives:
/home/ciro/.nvm/versions/node/v0.9.0/lib/node_modules/vaca/index.jsso we see that everything is completely contained inside the specific node version.
Tested in Ubuntu 17.10.
2I tried the same list commands on my ubuntu 14.04 but it was still throwing an error.
Commands I executed were:
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejsand the error i was getting:
Invalid version 0.12.2
Line 299: curl not found in /bin/nWhat I figured out was curl utility was not installed on my os.
I executed command:
apt-get install curl(use sudo as prefix if you are not su)
and then repeated the steps suggest in answer and it work ;)
CLEAN SIMPLE STEPS (which I use) :
Uninstall previous version of node -
sudo apt remove node && sudo apt autoremoveGo to and download the latest version of node.
Now open the terminal and change the directory where node is downloaded and then run-
tar -xvf node-v12.16.2-linux-x64.tar.xznow run this in terminal -
nano ~/.bashrcand append it with the following –
export PATH=/path/to/node-js/bin:$PATH
Where,/path/to/node-js/ is to be replaced where you extracted node in step 3.`run a last command
source ~/.bashrc
That's it.
Now you can check your node version by node -v
This one installs the latest node v0.12.* from nodesource.
sudo apt-get install -y curl
curl -sL | sudo bash -
sudo apt-get install -y nodejsFor node v4.x
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs 1 If using n does not work, you can install the latest version of nodejs (i. e. version 8) running the following commands:
curl -sL | sudo -E bash -
sudo apt-get install -y nodejsFurther instructions are here.
Using nvm is preferred method. First install nvm:
curl -o- | bashThen install nodejs:
nvm install nodeNow on, you can easy switch versions of node.
I suggest you first remove all nodejs installs then execute the below script once you edit with the desired nodejs version and its install parent directory
see all available nodejs versions
The below script will allow you to install any of those nodejs versions on linux or OSX
#!/bin/bash
# usage :
#
# edit two vars in below : NODE_VER and CODE_PARENT_DIR
#
# ... execute this script as yourself unless you choose a root-owned value for var CODE_PARENT_DIR
# whichever id you execute this as determines the id you will issue npm commands as: npm install -g foo-bar
#
# NOTE - nodejs comes bundled with npm ... so no need to do separate npm install
# This script runs fine on Linux or OSX
# ... copy all the lines starting here .. top of copy .... and ending ... end of copy ...
# and paste into your ~/.bashrc file so proper env vars get set
# ............... top of copy ........................ install_node.sh
# export NODE_VER=v7.2.0 # see available versions at
# export NODE_VER=v8.5.0 # edit this line next time you need to update nodejs
export NODE_VER=v9.3.0 # edit this line next time you need to update nodejs
# ... pick parent dir of nodejs install ... comment out or remove ONE of below
# export CODE_PARENT_DIR=/opt/code # root-owned dir ... requires you to sudo prior to npm install going forward
export CODE_PARENT_DIR=${HOME} # RECOMMENDED executing as yourself including npm install
# ......... following env vars are OK no edits needed ... only ever need to edit above vars
curr_OS=$( uname )
echo curr_OS $curr_OS
if [[ "${curr_OS}" == "Darwin" ]]; then OS_ARCH=darwin-x64
elif [[ "${curr_OS}" == "Linux" ]]; then OS_ARCH=linux-x64
else echo "ERROR - failed to recognize OS $curr_OS" exit 5
fi
if [[ -z ${CODE_PARENT_DIR} ]]; then echo "ERROR - failed to see env var CODE_PARENT_DIR" exit 5
fi
export NODE_CODEDIR=${CODE_PARENT_DIR}/nodejs
export COMSUFFIX=tar.gz
export NODE_NAME=node-${NODE_VER}
export NODE_PARENT=${NODE_CODEDIR}/${NODE_NAME}-${OS_ARCH}
export PATH=${NODE_PARENT}/bin:${PATH}
export NODE_PATH=${NODE_PARENT}/lib/node_modules
# ............... end of copy ........................ install_node.sh
# copy and paste above from ... top of copy ... to here into your file ~/.bashrc
echo
echo "NODE_CODEDIR $NODE_CODEDIR<--"
echo
echo "mkdir -p ${NODE_CODEDIR}"
echo mkdir -p ${NODE_CODEDIR}
echo
echo "cd ${NODE_CODEDIR}" cd ${NODE_CODEDIR}
echo
# this is compiled code NOT source
[ -f ${NODE_NAME}-${OS_ARCH}.${COMSUFFIX} ] && rm ${NODE_NAME}-${OS_ARCH}.${COMSUFFIX} # if file exists remove
echo "wget -q --show-progress " wget -q --show-progress
echo
echo "tar -C ${NODE_CODEDIR} -xf ${NODE_NAME}-${OS_ARCH}.${COMSUFFIX}" tar -C ${NODE_CODEDIR} -xf ${NODE_NAME}-${OS_ARCH}.${COMSUFFIX}
echo
[ -f ${NODE_NAME}-${OS_ARCH}.${COMSUFFIX} ] && rm ${NODE_NAME}-${OS_ARCH}.${COMSUFFIX} # if file exists remove
# ........... done ........... #
which node
node --version
# .... bottom of file install_node.sh If you are behind a proxy, maybe you could get this error when you run 'sudo n stable':
Error: invalid versionYou have to set the env variables like this:
export HTTP_PROXY=
export HTTPS_PROXY=And then run the command passing these variables to the root user:
sudo -E n stable 1 The selected answer did not work for me, I tried restarting terminal and PC but no success.
I have installed (as recommended in the docs) npm and node with node version manager. In this case, one can update node and npm simply with
nvm install stableI explained here how to switch to reinstall with node-verion-manager if you have installed npm/node with Node installer.
I tried to install via nvm, as described above, but faced some error in Ubuntu 18.04. Then I went through this process:
sudo apt purge nodejs npm
curl -o- | bash
nvm install nodeAfter running this command, you might get this error:
Command 'nvm' not found, did you mean:In that case you can run this command:
source ~/.nvm/nvm.shOR you can put it in the /.bashrc or ~/.profile file to automatically load it.
After that you can run the following commands:
nvm install node
nvm alias default node