A good[ish] website

Web development blog, loads of UI and JavaScript topics

Install Node and npm to an Ubuntu box

Filed under: Server— Tagged with: node, npm, linux

This post looks how it’s best to install Node with nvm.

Ideally, Node could be installed with $ apt-get install nodejs, but the node in apt-get is not up to date, hence the preferred tool is nvm, Node Version Manager.

Install nvm

Few packages are needed for the installation process:

$ sudo apt-get update
$ sudo apt-get install build-essential libssl-dev

Then grab the nvm install script:

$ curl | sh

That command will also run it.

Now exit your box and log back in, or source the ~/.profile:

$ source ~/.profile

Install Node

The latest Node version can be queried with the nvm tool we just installed:

$ nvm ls-remote

It spews out a long list of Node version, the last one is the latest, at the moment it seems to be v0.11.14. Now it’s extremely easy to get Node installed:

$ nvm install 0.11.14

That’s pretty much it.

Troubleshooting the node installation

If getting the following error when trying to install a package via npm:

npm http GET

npm ERR! Error: failed to fetch from registry: express
npm ERR!     at /usr/share/npm/lib/utils/npm-registry-client/get.js:139:12
npm ERR!     at cb (/usr/share/npm/lib/utils/npm-registry-client/request.js:31:9)
npm ERR!     at Request._callback (/usr/share/npm/lib/utils/npm-registry-client/request.js:136:18)
npm ERR!     at Request.callback (/usr/lib/nodejs/request/main.js:119:22)
npm ERR!     at Request.<anonymous> (/usr/lib/nodejs/request/main.js:212:58)
npm ERR!     at Request.emit (events.js:88:20)
npm ERR!     at ClientRequest.<anonymous> (/usr/lib/nodejs/request/main.js:412:12)
npm ERR!     at ClientRequest.emit (events.js:67:17)
npm ERR!     at HTTPParser.onIncoming (http.js:1261:11)
npm ERR!     at HTTPParser.onHeadersComplete (http.js:102:31)
npm ERR! You may report this log at:
npm ERR!     <>
npm ERR! or use
npm ERR!     reportbug --attach /var/log/npm-debug.log npm
npm ERR!
npm ERR! System Linux 3.8.0-29-generic
npm ERR! command "node" "/usr/bin/npm" "install" "-g" "express"
npm ERR! cwd /var/log
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! message failed to fetch from registry: express
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /var/log/npm-debug.log
npm not ok

It might be that Node was installed via apt-get, and the apt-get version of Node is most certainly out of date and can't locate the registry.

Comments would go here, but the commenting system isn’t ready yet, sorry.

  • © 2022 Antti Hiljá
  • About
  • All rights reserved yadda yadda.
  • I can put just about anything here, no one reads the footer anyways.
  • I love u!