Node.js is a JavaScript runtime for server-side programming. It allows developers to create scalable backend functionality using JavaScript, a language many are already familiar with from browser-based web development.
In this guide, we will show you two different ways of installing Node.js on an Ubuntu 20.04 LTS server:
- using Node.js ubuntu default software repository
- using alternate PPA software repository to install specific versions of the Node.js package
Method 1./ Install Node.js and npm using apt
01- The latest version of Node-js available from the official Ubuntu 20.04 LTS repositories is Node.js version 10.19. So, use the below commands to install Node.js and npm:
$ sudo apt update $ sudo apt install nodejs npm
02- Once done, verify the installation by running:
$ nodejs --version
v10.19.0
Method 2./ Install latest Node.js and npm using an alternate PPA
01- Run the following command as a user with sudo privileges to download and execute the NodeSource installation script:
$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - ## Run `sudo apt-get install -y nodejs` to install Node.js 14.x and npm ## You may also need development tools to build native addons: sudo apt-get install gcc g++ make ## To install the Yarn package manager, run: curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get update && sudo apt-get install yarn
setup_12.x
.
02- Once the NodeSource repository is enabled, install Node.js and npm as below:
$ sudo apt install nodejs
03- Verify that you’ve installed the new version by running node with the -v
version flag:
$ node --version
v14.3.0
04- The NodeSource package contains both the Node.js binary and npm, so you don’t need to install npm separately. To check the version of npm, run the below command:
$ npm --version
6.14.5
Conclusion
You have successfully learned how to install Node.js and npm on Ubuntu 20.04 LTS using different methods, using Node.js ubuntu default software repository or by using an alternate PPA software repository to install specific versions of the Node.js package.
You might want to check the following guides: