One-line install Node.js on Linux
In this snippet, we’re installing the latest version of Node, though you can choose any version listed here: https://nodejs.org/dist/.
# Use latest version
$ export VER=$(curl -s https://nodejs.org/download/release/index.json | grep -Po '\d*\.\d*\.\d*' | head -n1) && echo $VER
# Pick a version
$ export VER=20.9.0
# 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 --version
v22.8.0
$ npm --version
10.8.2
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