In this tutorial, we will show you several different ways of installing Node.js and npm on Ubuntu 18.04\. The same instructions apply for any Ubuntu-based distribution, including Kubuntu, Linux Mint and Elementary OS.
Npm is the default package manager for Node.js and the world’s largest software registry.
In this tutorial, we will show you several different ways of installing Node.js and npm on Ubuntu 18.04. The same instructions apply for any Ubuntu-based distribution, including Kubuntu, Linux Mint and Elementary OS.
If you need Node.js only as a local runtime for deploying Node.js applications then the simplest option is to install Node.js from the NodeSource repository. Developers should prefer installing Node.js using the NVM script. Choose the installation option that is appropriate for your environment. It is best to consult the documentation of the Node.js application that you use to find out which Node.js versions are supported.
NodeSource is a company focused on providing enterprise-grade Node support and they maintain a repository containing the latest versions of Node.js.
Use this repository if you need to install a specific version of Node.js. At the time of writing, NodeSource repository provides the following versions - v12.x, v11.x, v10.x, and v8.x. We'll install the current LTS version of Node.js, version 10.x, Carbon.
To install Node.js and npm from the NodeSource repository, follow these steps:
Enable the NodeSource repository by running the following
curl as a user with sudo privileges:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
The command will add the NodeSource signing key to your system, create an apt sources repository file, install all necessary packages and refresh the apt cache.
If you need to install another version, for example 12.x, just change
Once the NodeSource repository is enabled, install Node.js and npm by typing:
sudo apt install nodejs
The nodejs package contains both the
Verify that the Node.js and npm were successfully installed by printing their versions:
NVM (Node Version Manager) is a bash script used to manage multiple active Node.js versions. With NVM you can install and uninstall any specific Node.js version you want to use or test.
To install Node.js and npm using NVM on your Ubuntu system, perform the following steps:
To download and install the
nvm script run:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
The command above will clone the NVM repository from Github to the
=> Close and reopen your terminal to start using nvm or run the following to use it now: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
As the output above says, you should either close and reopen the terminal or run the commands to add the path to
nvm script to the current shell session. You can do whatever is easier for you.
Once the script is in your
PATH, verify that
nvm was properly installed by typing:
Now that the
nvm is installed you can install the latest available version of Node.js, by typing:
nvm install node
The output should look something like this:
Downloading and installing node v12.8.1... Downloading https://nodejs.org/dist/v12.8.1/node-v12.8.1-linux-x64.tar.xz... ######################################################################### 100.0% Computing checksum with sha256sum Checksums matched! Now using node v12.8.1 (npm v6.10.2) Creating default alias: default -> node (-> v12.8.1)
Once the installation is completed, verify it by printing the Node.js version:
Let's install two more versions, the latest LTS version and version 8.10.0
nvm install --lts nvm install 8.10.0
To list installed Node.js versions type:
The output should look something like this:
-> v8.10.0 v10.16.3 v12.8.1 default -> node (-> v12.8.1) node -> stable (-> v12.8.1) (default) stable -> 12.8 (-> v12.8.1) (default) iojs -> N/A (default) unstable -> N/A (default) lts/* -> lts/dubnium (-> v10.16.3) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.17.1 (-> N/A) lts/carbon -> v8.16.1 (-> N/A) lts/dubnium -> v10.16.3
The entry with an arrow on the right (-> v8.10.0) is the Node.js version used in the current shell session and the default version is set to v12.8.1. Default version is the version that will be active when opening new shells.
You can change the currently active version with:
nvm use 10.16.3
Now using node v10.16.3 (npm v6.9.0)
If you want to change the default Node.js version use the following command:
nvm alias default 10.16.3
Node.js and npm packages are available from the default Ubuntu 18.04 repositories.
At the time of writing, the version included in the Ubuntu repositories is
v8.10.0 which is the previous TLS version.
npm run the following commands:
sudo apt update sudo apt install nodejs
The Node.js executable from the Ubuntu repositories is named
nodejs instead of
node because of a conflict with another package.
Verify the installation by executing:
To be able to compile and install native add-ons from npm you need to install the development tools.
The following command will install all the necessary packages including the GCC compilers:
sudo apt install build-essential
If for some reasons you want to uninstall Node.js and npm packages, you can use the following command:
sudo apt remove nodejs npm
We have shown you three different ways to install Node.js and npm on your Ubuntu 18.04 server. The method you choose depends on your requirements and preferences. Even though installing the packaged version from the Ubuntu or NodeSource repository is easier, the nvm method gives you more flexibility for adding and removing different Node.js versions on a per-user basis.
Thank you for reading !
It also provides an option to auto-select the node version using the .nvmrc configuration file. This tutorial will help you to install NVM on Ubuntu 20.04 Linux system. Also, allow you to install different node versions and other useful examples.
In this tutorial, we will show you how to install Microsoft Teams on Ubuntu 20.04 machine. we can install teams using Debian installer file or by adding microsoft repository.
In this tutorial, you will learn how to install Node onto Ubuntu 19.04 Disco Dingo. We will cover installation from the default repositories and, for those wanting more recent releases, how to install from the NodeSource repositories.
Looking to build dynamic, extensively featured, and full-fledged web applications? **[Hire NodeJs Developer](https://hourlydeveloper.io/hire-dedicated-node-js-developer/ "Hire NodeJs Developer")** to create a real-time, faster, and scalable...
In this tutorial, we will explore three different ways of installing Node.js and npm on Ubuntu 20.04. From the standard Ubuntu repositories, from the NodeSource repositories and by using the nvm script.