Empowering you to understand your world

How To Install Node.js

By Nicholas Brown – Follow me on Twitter.

Node.js Tutorials: How To Install Node.js On Ubuntu Or Debian

You can install Node.js on Ubuntu using one of the following methods:

How To Install Node.js Using The APT Package Manager

You can install Node.js using the APT package manager using the following command. This will install the latest version supplied by the Ubuntu package maintainers, which may be older than the latest version. If you want to install the latest version, scroll down further to see how to download it directly from the Node.js website.

sudo apt install nodejs

After typing that you should see ‘the following NEW packages will be installed’, and ‘nodejs’ should be among them. It will also suggest ‘npm’, which is useful to have as well. Press ‘Y’ and enter to install it.

How To Update Node.js Using The Package Manager

You can update Node.js using the Ubuntu or Debian package manager by typing the following command:

sudo apt update
sudo apt --only-upgrade install nodejs

How To Install The Latest Version Of Node.js On Ubuntu Or Debian

If the Ubuntu repositories don’t include the latest versions of Node.js, you can get the binary from the Node.js download page and extracting it. You can also use the Node Version Manager (NVM). You will be provided with the option to select the long-term support (LTS) version or the current version if downloading the binary from the website. The LTS version is recommended because it is more stable.

To install Node.js using NVM or install multiple versions of Node.js, please follow the instructions in the NVM article to install NVM, and then run the following command with the version of Node.js you’d like to install:

nvm install v20.2.0

How To Update Node.js Using NVM

To update your Node.js version using NVM, you’d type the following command, which installs the latest version. The second line will alternately install the latest LTS version:

nvm install node
nvm install node --lts

If you want to set up a repository that does have the latest version so that it is automatically updated, you can use Nodesource.

How To Check Node.js Version

You can check the version of Node.js your system is using with the following command:

node -v

How To Run Node.js

You can run Node.js by itself by typing ‘nodejs’ or ‘node’ on some installations, or you can start your project along with it as shown below:

nodejs yourapp.js

How To Run Node.js Using NVM

You can run a Node.js app from NVM using the following command (change 20.2.0 to the version you have):

nvm run 20.2.0 yourapp.js
Subscribe to our newsletter
Get notified when new content is published