22

When I install nodejs and npm with apt-get

sudo apt-get update
sudo apt-get install nodejs modejs-legacy npm
I have the versions

I get the following versions

npm -v
1.3.10

nodejs -v
v0.10.25

I know how to update these manually, but why does the apt-get package manager have old versions of these packages?

user1283776
  • 19,640
  • 49
  • 136
  • 276
  • Related to the need expressed by your question, you may want to look at https://github.com/creationix/nvm which installs whatever node version you want in userland, and allows switching versions. It is considered a better pattern, even in production. Ruby and other languages uses such techniques too (ex. rvm) – Offirmo May 03 '16 at 19:29

4 Answers4

26

It's better to use the ppa from nodesource. They have done a great job keeping it updated and offering not only LTS but also latest versions of node available. https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

As easy as running this from your cli:

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

UPDATE:

The reason WHY the package manager has old versions of the binaries is due to the fact it takes time for the maintainers of the provided packages to properly build and test new ones with updated versions.

The good thing is that you can consume and install packages from other repositories (ppa).

onel0p3z
  • 566
  • 5
  • 11
1

Other instructions on the internet will tell you to install node 7.x by downloading a script and piping it into sudo. This is less typing but might give that script and anyone who may have compromised the website or set up a MITM attack root access to your computer.

Because the maintainers of the main apt repository audit and test packages before adding them, it can take some time for them to approve the latest versions. You can download node 7.x from an independently maintained repo:

I copy pasted from this answer

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 68576280
sudo apt-add-repository "deb https://deb.nodesource.com/node_7.x $(lsb_release -sc) main"
sudo apt-get update
sudo apt-get install nodejs
actual_kangaroo
  • 5,971
  • 2
  • 31
  • 45
0

One thing to consider is that while adding the repository using $(lsb_release -sc) works in ubuntu, it may not work on Ubuntu based distributions such as Linux Mint. The script from nodesource does a translation from the Ubuntu based distribution name to the corresponding Ubuntu distribution name.

For example: "Linux Mint" "sylvia" is mapped to "Ubuntu" "xenial"

Which means that if you want to use the instructions as shown in the response in an Ubuntu based distribution, you need to replace $(lsb_release -sc) with the actual base Ubuntu distribution.

For example, to install in Linux Mint sylvia, you need to enter

sudo apt-add-repository "deb https://deb.nodesource.com/node_7.x xenial main"
0

ran into the same issue, got the solution here. sorry if it looks like copied from somewhere else

wget -c https://nodejs.org/download/release/v17.3.1/node-v17.3.1-linux-x64.tar.gz
tar xvf node-v17.3.1-linux-x64.tar.gz 
mkdir  -p /etc/node/
mv node-v17.3.1-linux-x64/* /etc/node/


echo 'export NODEJS_HOME=/etc/node/bin' >> /etc/profile
echo 'export PATH=$NODEJS_HOME:$PATH' >> /etc/profile
source /etc/profile
nano /etc/profile
MartianMartian
  • 1,753
  • 1
  • 18
  • 26