How can I install npm on 17.10?
Note: This answer has been updated since when it was first posted because there is now a better way of installing the latest version of npm which is built-in with the node snap package for installing Node.js. After running the below commands running npm -v
will show that the latest version of npm is installed and being used.
Node.js is available as a snap package in all currently supported versions of Ubuntu. Specific to Node.js, developers can choose from one or more of the currently supported releases and get regular automatic updates directly from NodeSource. Node.js versions 6, 8, 9, 10, 11, 13 and 14 are currently available, with the Snap Store being updated within hours or minutes of a Node.js release.
Node can be installed with a single command, for example:
sudo snap install node --classic --channel 11/stable # also install snapd in 14.04
The node snap can be accessed by the command node
, for example:
$ node -v v11.5.0
An up-to-date version of npm will installed as part of the node snap. npm should be run outside of the node repl, in your normal shell. After installing the node snap run the following command to enable npm update checking:
sudo chown -R $USER:$(id -gn $USER) /home/your-username/.config
Replace your-username
in the above command with your own username. Then run npm -v
to check if the version of npm is up-to-date. As an example I checked that npm was up-to-date, checked the version of an already installed package named yarn with the command npm list yarn
and then updated the existing yarn package to the latest version with the command npm update yarn
Users can switch between versions of Node.js at any time without needing to involve additional tools like nvm (Node Version Manager), for example:
sudo snap refresh node --channel=10/stable
Users can test bleeding-edge versions of Node.js that can be installed from the latest edge channel which is currently tracking Node.js version 12 by switching with:
sudo snap switch node --edge
This approach is only recommended for those users who are willing to participate in testing and bug reporting upstream.
Node.js LTS Schedule
Release LTS Status Codename LTS Start Maintenance Start Maintenance End 6.x Active Boron 2016-10-18 April 2018 April 2019 7.x No LTS 8.x Active Carbon 2017-10-31 April 2019 December 2019 9.x No LTS 10.x Active Dubnium October 2018 April 2020 April 2021 11.x No LTS 2019-04-01 2019-06-30 12.x 2019-10-22 2021-04-01 2022-04-01 13.x No LTS 2020-04-20 2020-06-01 14.x Current Fermium 2020-10-20 2021-10-20 2023-04-30
I had the same issue. libssl is troublesome since lots of packages want different versions of it. The top troublemakers for me are Spotify, Viber, DotNet Core, php5.6 (legacy system).
Anyway, this solution seems to have worked:
Based on the answer by Jonathan Leaders, if you look at the script that it's downloading, you'll see it mention 2 key points: the repository, and the key.
For some reason after running just those commands, nodejs was still referring to the one in the official Ubuntu repositories, and it was an old version, with conflicting requirements for libssl.
Add them manually for reliable results (as root):
echo 'deb https://deb.nodesource.com/node_9.x artful main' > /etc/apt/sources.list.d/nodesource.list
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
After that, simply apt-get update
and then apt-get install nodejs
After that you'll have npm as well without installing anything additionally.
Note that this installs Nodejs 9.0, but I'm sure that the same method works for other versions as well. You just have to switch the version number in the repository source in /etc/apt/sources.list.d/nodesource.list