Harness the Combinatoric Power of Command-Line Tools and Utilities
Install Node.js on macOS, Windows, and Linux
Published April 28, 2024
Node.js is a JavaScript runtime for server-side programming. It lets you create scalable backend applications and tools using JavaScript.
Command line tools written in JavaScript need Node.js installed on the system in order for them to run. In this tutorial you’ll install Node.js on your system so you can use it to run command line tools.
Wht You Need
- On macOS, you’ll need Homebrew installed, which you can do by following the Install Homebrew tutorial.
- On Windows, if you want to use the Linux version of Node.js, you’ll need WSL installed, which you can do by following the Install WSL tutorial.
Install Node.js on macOS
Install Node.js on macOS using Homebrew using the following command:
brew install node
This installs Node.js and the npm
package manager.
Install Node.js on Ubuntu
To install Node.js, you’ll use the Nodesource binary distribution, as the built-in version in Ubuntu is often outdated.
The official instructions ask you to download and execute an installation script that adds their repository to your system. Running third-party scripts as the root user, or with elevated permissions, is a bad practice.
To ensure your safety, download the script first and inspect its contents.
First, download the script:
curl -fsSL https://deb.nodesource.com/setup_22.x -o node22.sh
View its contents with less
:
less node22.sh
Once you’re comfortable with the script’s contents, execute the script:
sudo bash node22.sh
Once the script completes, install Node.js using apt
:
sudo apt install -y nodejs
This installs both Node.js and the npm
package management tool.
Install Node.js on Windows
On Windows, you can install Node.js by downloading and running the official Windows installation tool.
Conclusion
WIth Node.js installed, you can now use it to execute a number of powerful command-line tools written in JavaScript and TypeScript.