0

I'm a brand new to Linux so this may be a rookie question...

On a new installation of Ubuntu 18.04 LTS I want to install NodeJS. I ran node --version to verify that it is not installed:

Command 'node' not found, but can be installed with:
sudo apt install nodejs

So, it's not installed and the terminal output recommends how to install it.
Some other online sources suggest using wget or curl to install it like so:

# using wget
wget https://nodejs.org/dist/v12.13.1/node-v12.13.1-linux-x64.tar.xz

# using curl
curl -o node-v12.13.1-linux-x64.tar.xz https://nodejs.org/dist/v12.13.1/node-v12.13.1-linux-x64.tar.xz

# extract
tar xf node-v12.13.1-linux-x64.tar.xz

Are there good reasons to use wget or curl instead of apt install?

3 Answers 3

3

The version you'll install through apt is the version packaged for the OS by Ubuntu. On Ubuntu 18.04, that appears to be nodejs 8.10.0. The version provided directly from the nodejs website (the curl and wget options) is the latest version, but if you download it you'll have to keep it up to date manually.

I don't use NodeJS so there may be other recommendations from the community, but as a general rule it's best to install the version of a package from apt unless you specifically know you need to do otherwise.

Reasons why you might need to do otherwise include you potentially specifically needing a newer version of nodejs. This happens sometimes, but if you do need it, it's worth signing up for their mailing list or another way of getting notified when a newer version is released so you can update it rather than have potential security issues.

1

Generally the use of wget on curl on your question is the same, they both retrieving/downloading files from the web server.

So your question probably is: Difference between NodeJS installed from apt and from their official site ?

Installed from apt

Node.js installed from apt should work out of the box in 99.9% case because it's specifically designed for one's distribution (in your case it's 18.04). So if you seek easy installing and doesn't need specific version of Node.js, this would be your best choice.

As the time of writing, Ubuntu's vanilla repository offer Node.js version 8.10.0

$ apt-cache policy nodejs
nodejs:
  Installed: (none)
  Candidate: 8.10.0~dfsg-2ubuntu0.4
  Version table:
     8.10.0~dfsg-2ubuntu0.4 500

Installed from Node.js page

This is the best choice if you certainly needing a newer version of Node.js— otherwise the apt widely recommended over manual installing.

By the way, you have to repeat the process once again in case that you want to upgrade to newer version, whereas apt will handle that for you.


You could add Node.js repository to your Ubuntu machine, this way you can install specific version of Node.js with apt.

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install nodejs

Replace 12.x with your desired version. Then, verify your version using nodejs -v command.

0

The version of nodejs packaged in the official Ubuntu repositories may vary from an Ubuntu version to another

Sometimes -ex contributing to open source project- its mandatory to use a specific and older version of nodejs which will meet the dependencies of the project

In that case of a specific version need, it will have to be manually installed
Find all avaiable versions here:
https://nodejs.org/dist/

There is some information about manual install on the nodejs github
https://github.com/nodejs/help/wiki/Installation
In short:

Manual install of a specific version (lets say deprecated 6.17.1)

# 1. Download the binary archive from https://nodejs.org/en/download/releases/
wget https://nodejs.org/dist/latest-v6.x/node-v6.17.1-linux-x64.tar.xz

# 2. Extract archive where you want
#    Here extracted to /usr/local/lib/nodejs/VERSION
VERSION=v6.17.1
DISTRO=linux-x64
sudo mkdir -p /usr/local/lib/nodejs
sudo tar -xJvf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs 

# 3. Set the environment variable ~/.profile or /etc/profile
sudo tee -a /etc/profile << EofProfile
# Nodejs
export PATH=/usr/local/lib/nodejs/node-v6.17.1-linux-x64/bin:$PATH
EofProfile

# 4. Add symlinks to /usr/bin
sudo ln -s /usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin/node /usr/bin/node
sudo ln -s /usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin/npm /usr/bin/npm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .