You can follow one of the following options to install NodeJS in Ubuntu OS, I would suggest follow the first option 2 if you want NodeJs on Your local dev machine or development server.
If you are installing it on your production server then I guess the Option 1 is better way to go.
Option 1: Installing Node.js with Apt Using a NodeSource BASH
apt update
cd ~
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - &&\
sudo apt-get install -y nodejs
The NodeJS is ready to use you can verify installation by using node -v and npm -v
you should get the latest LTS version installed.
Option 2: Installing Node Using the Node Version Manager
To install NVM using curl
, run the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
alternatively, you can also install NVM using wget
, run the following command:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
Source the new instructions NVM added to .bashrc
source ~/.bashrc
You have successfully installed NVM on your machine, to install the latest version of Node, run the following:
nvm install node
Now, you can ask NVM which versions of Node are available:
nvm list-remote
You can install your preferred version from list using following command
nvm install _your_preferred_version_of_nodejs
Review all installed versions of Node with the ls
command.
nvm ls
More information about Node NVM Also learn more about NodeSource