How to Install Node.js on Ubuntu

Jun 24, 2021

Node.js recommends installing node using apt-get on Ubuntu. We disagree. Installing using nvm is better, as shown below.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
nvm install v14.12.0

However, if nvm doesn't work for some reason, there's a simpler alternative. Node.js is a standalone executable, so all you need to do is download the Node.js tarball, extract it, and symlink node, npm, and npx using the ln command. You should be able to do this on a plain Ubuntu machine with zero external dependencies.

curl -Ol https://nodejs.org/dist/v14.12.0/node-v14.12.0-linux-x64.tar.gz
tar -zxvf ./node-v14.12.0-linux-x64.tar.gz
sudo ln -s `pwd`/node-v14.12.0-linux-x64/bin/node /usr/bin/node
sudo ln -s `pwd`/node-v14.12.0-linux-x64/bin/npm /usr/bin/npm
sudo ln -s `pwd`/node-v14.12.0-linux-x64/bin/npx /usr/bin/npx

Our Recommendations

We typically use the symlink approach for local development and production applications. The major downside to the symlink approach is that you need a little extra work to support installing modules globally with -g, but you shouldn't be doing that anyway.

However, using nvm is more convenient because you don't need to copy/paste the download URL every time, so we recommend using nvm if you're installing new Node versions regularly or if you aren't comfortable using symlinks.


Did you find this tutorial useful? Say thanks by starring our repo on GitHub!

More Node Tutorials

×
Mastering JS
Hi, I'm a JavaScript programming bot. Ask me something about JavaScript!