Node.js is an open-source and cross-platform JavaScript runtime environment. Usually, JavaScript is associated with web development and browser executions.
But Node.js enables its user to run JavaScript as a stand-alone application, on any medium. It means you can run JavaScript outside the browser.
Node Package Manager (npm) is both an online repository for modules and packages of Node.js, and a command-line utility for installation, version, and dependency management.
Npm is easy to use and makes working with Node.js very convenient. Additionally, npm comes with Node.js installation so you do not have to install it separately.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux system Node JS and Npm queries.
In this context, we shall look into how to install Node.js and Npm in your Ubuntu operating system.
You will need a curl command to enable the NodeSource repository. If you lack curl on your system, install curl on your system using the following command:
$ sudo apt-get install curlTo enable the NodeSource repository and update the apt-cache. run the following command:
$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -Now you can go ahead and install the Node.js package with the following apt command:
$ sudo apt install nodejsYou can see the Node.js version with the following command:
$ node --versionAs npm comes with the Node.js installation, you can check the npm version with the following command:
$ npm --versionIf you want your repository to be self-maintained and updated so that you can work with the latest version of Node.js, you can use the NodeSource PPA for Node.js installation.
Install the NodeSource PPA with the following curl command:
$ curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.shOpen the Nodesource setup script with nano editor and verify the configurations:
$ nano nodesource_setup.shTo add the PPA to the configuration list and update the local cache, run the script:
$ sudo bash nodesource_setup.shNow you can install Node.js with the following command:
$ sudo apt install nodejsTo verify the installation and version of Node.js, run:
$ node -vNode Version Manager (NVM) is a script that helps with the installation and management of multiple versions of Node.js in your system.
Download NVM from the GitHub repository with the following curl command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bashYou can see that the installation has made changes to the .bashrc file. Source your.bashrc file with the following command to proceed with the installation:
$ source ~/.bashrcTo see available versions of Node.js, run the following command:
$ nvm list-remoteSelect the version and run the following command with your selected version:
$ nvm install v17.0.1To see all the Node.js installations in your system, run the following command:
$ nvm listYou can see the current version that is in use mentioned in the first line of the output.
You can switch to another installed version and use it with the following command.
$ nvm use 17.0.1This article covers the different ways to install Node.js in your Ubuntu system. Node.js is a popular back-end JavaScript runtime used for creating web servers and scalable network apps. The environment supports server-side scripting - producing dynamic content for web pages before they are served to the user.
NPM is a package manager for JavaScript and the default package manager for Node.js. As such, NPM is installed alongside Node.js as a recommended feature.