One-line install Node.js on Linux

Jaime Pillora
Jaime Pillora

--

In this snippet, we’re installing LTS version 10.15.0 of Node though you can choose any version listed here: https://nodejs.org/dist/.

# Pick a version
$ export VER=10.15.0
# Or use latest LTS
$ export VER=$(curl https://nodejs.org/en/ | grep -Po '\d*\.\d*\.\d* LTS' | head -n1 | cut -f1 -d' ') && echo $VER
# Install
$ curl https://nodejs.org/dist/v$VER/node-v$VER-linux-x64.tar.xz | tar --file=- --extract --xz --directory /usr/local/ --strip-components=1
# Confirm
$ node -v
v10.15.0
$ npm -v
6.4.1
  • If xz isn’t installed you’ll need to apt-get install xz-utils
  • Using long-form of each option for readability
  • sudo tar is required when not running as root
  • On macOS, use grep -Eo instead of -Po
  • You can also use wget -qO- instead of curl
  • Extracts to /usr/local so binaries will end up in /usr/local/bin

--

--