Wednesday, 10 October 2018

How to install Node.js on Ubuntu 18.04

I installed npm without installing Node.js by executing:

$ sudo apt install npm

...but this installed its very old version:

$ npm --version
3.5.2

npm comes with Node.js and I wanted to install their latest version. After reading this Q&A thread I decided to use nvm.

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 12819  100 12819    0     0  34093      0 --:--:-- --:--:-- --:--:-- 34093
=> Downloading nvm from git to '/home/bojan/.nvm'
=> Cloning into '/home/bojan/.nvm'...
remote: Enumerating objects: 267, done.
remote: Counting objects: 100% (267/267), done.
remote: Compressing objects: 100% (242/242), done.
remote: Total 267 (delta 31), reused 86 (delta 15), pack-reused 0
Receiving objects: 100% (267/267), 119.47 KiB | 385.00 KiB/s, done.
Resolving deltas: 100% (31/31), done.
=> Compressing and cleaning up git repository
=> Appending nvm source string to /home/bojan/.bashrc
=> Appending bash_completion source string to /home/bojan/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Let's now install the latest version of Node.js. To check which one is the latest, go here. At the time of writing it was 10.11.0. In a new terminal session do the following:

$ nvm install 10.11.0
Downloading and installing node v10.11.0...
Downloading https://nodejs.org/dist/v10.11.0/node-v10.11.0-linux-x64.tar.xz...
################################################################################################################# 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v10.11.0 (npm v6.4.1)
Creating default alias: default -> 10.11.0 (-> v10.11.0)

Let's check the versions now:

$ node --version
v10.11.0

$ npm --version
6.4.1

Post a Comment