I am using 16.04 but I wouldn't mind switching to 14.04 if needed.
I would like to install two packages, NodeJS and npm.
- What steps can I follow to accomplish this?
- Also, how do I update NPM after installing?
I am using 16.04 but I wouldn't mind switching to 14.04 if needed.
I would like to install two packages, NodeJS and npm.
There are multiple ways to install NodeJS and npm on Ubuntu.
The recent versions of Ubuntu come with NodeJS (package nodejs
) and npm (package npm
). You can simply install those with apt
. But, depending on which Ubuntu version you're running, those packages may contain outdated versions of NodeJS and npm.
NodeSource offers a personal package archive (PPA) with more current versions of NodeJS and npm. You can install the PPA like this (for example for NodeJS 8.x)
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get update
sudo apt-get install -y nodejs
You can find further information at the projects GitHub repo.
Probably the most versatile option is to use the Node Version Manager (nvm). That's a simple bash script that enables you to install multiple versions of NodeJS in parallel and switch between them.
# install nvm, for example version 0.33.2
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
# list installed versions of NodeJS
nvm ls
# list available versions of NodeJS
nvm ls-remote
# install NodeJS, for example version 8.1.4
nvm install 8.1.4
# use installed version of NodeJS, for example 6.11.1
nvm use 6.11.1
Regarding the relationship between NodeJS and npm, to my best knowledge the two are quite tightly coupled. That means it doesn't make too much sense to update npm on its own. If you need a newer npm for whatever reason, use a newer NodeJS version that comes with a newer npm version.
Below commands will install nodejs v7.10 along with npm v4.2.
# sudo apt-get install python-software-properties
# curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
# sudo apt-get install nodejs
# node -v
# npm -v
To update NPM use command:
# npm install -g npm
To install using apt, enter the following commands.
$ sudo apt update
$ sudo apt-get install nodejs
$ node -v
Install nvm using:
$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
$ nvm
#If the nvm command above outputs "nvm: command not found" (or nothing) then run:
$ command -v nvm
#To install node, enter:
$ nvm install nodenvm run node --version
#Run with:
$ nvm run node --version
Add the NodeSource repo, & then install by using these commands:
#Add the signing key.
$ wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
#Now add the latest node repository (v8.x) with:
$ sudo add-apt-repository "deb https://deb.nodesource.com/node_8.x xenial main"
nodejs can be installed via snap package manager on almost any linux based distro. Actually you can switch between multiple versions of node fairly fast viasnap refresh node --channel desiredNodeVersion
Current example:
snap refresh node --channel 12
node --version // it prints v12.13.1
snap refresh node --channel 13
node --version // it prints v13.2.0