Skip to content

Instantly share code, notes, and snippets.

@nicc777
Last active June 4, 2020 07:41
Show Gist options
  • Save nicc777/7311918803ec3194413c4370a4fb7d14 to your computer and use it in GitHub Desktop.
Save nicc777/7311918803ec3194413c4370a4fb7d14 to your computer and use it in GitHub Desktop.
Getting the latest Node Installation on Ubuntu (18.04)

Context

I often need to play and experiment and using different environments help. In the era of virtualisation we have many options. For this exercise, I'm using Ubuntu Multipass which allow you to vey quickly create virtual machines.

The steps described here will not only install the latest version of Node.js but will also setup the environment to install any global packages in ~/.npm-packages.

Starting a new Multipass Ubuntu Instance

$ multipass launch -n nodejs
Launched: nodejs

Logging in and installing the latest Node.js

Getting a shell into the new virtual machine is a quick one liner:

$ multipass shell nodejs

The rest of the instructions is essentially a summary of what worked for me after reading this Stackoverflow discussion

The Node.js installation steps were taken from this site (last accessed 2020-06-04)

Prepare the environment:

$ mkdir ~/.npm-packages
$ sudo apt-get install gcc g++ make nodejs
$ curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
$ sudo apt-get update && sudo apt-get install yarn
$ npm config set prefix .npm-packages

I have also added the next lines to ~/.bashrc:

$ cat >>.bashrc <<EOL
alias ls='/bin/ls -lahrt --color'
export NPM_PACKAGES="${HOME}/.npm-packages"
export NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath`
# command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
EOL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment