The preferred method for installing Node.js, now, is to use the versions available in package managers, such as apt-get
, or Macports. Package managers simplify your life by helping to maintain the current version of the software on your computer, ensuring to update dependent packages as necessary, all by typing a simple command such as apt-get update
. Let's go over this first.
The MacPorts project (http://www.macports.org/) has for years been packaging a long list of open source software packages for Mac OS X, and they have packaged Node.js. After you have installed MacPorts using the installer on their website, installing Node.js is pretty much this simple:
$ sudo port search nodejs npm nodejs @4.4.3 (devel, net) Evented I/O for V8 JavaScript nodejs-devel @5.10.0 (devel, net) Evented I/O for V8 JavaScript Found 2 ports. -- npm @2.15.2 (devel) node package manager npm-devel @3.8.6 (devel) node package manager $ sudo port install nodejs npm .. long log of downloading and installing prerequisites and Node $ which node /opt/local/bin/node $ node --version v4.4.3
Homebrew is another open source software package manager for Mac OS X, which some say is the perfect replacement for MacPorts. It is available through their home page at http://brew.sh/. After installing Homebrew using the instructions on their website and ensuring that Homebrew is correctly set up, use the following:
$ brew search node leafnode node
$ brew install node ==> Downloading https://homebrew.bintray.com/bottles/node-5.10.1.el_capitan.bottle.tar.gz ######################################################################## 100.0% ==> Pouring node-5.10.1.el_capitan.bottle.tar.gz ==> Caveats Please note by default only English locale support is provided. If you need full locale support you should: `brew reinstall node --with-full-icu` Bash completion has been installed to: /usr/local/etc/bash_completion.d ==> Summary bin /usr/local/Cellar/node/5.10.1: 3,663 files, 35.7M
Once installed this way, the Node.js command can be run as follows:
$ node --version v5.5.0
Node.js is now available through most of the package management systems. Instructions on the Node.js website currently list packaged versions of Node.js for a long list of Linux, as well as FreeBSD, OpenBSD, NetBSD, Mac OS X, and even Windows. Visit https://nodejs.org/en/download/package-manager/ for more information.
For example, on Debian and other Debian-based Linux' (such as Ubuntu), use the following commands:
# curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - # sudo apt-get install -y nodejs # sudo apt-get install -y build-essential
In earlier Node.js releases, a Launchpad PPA maintained by Chris Lea was used instead. That PPA has transitioned to become Nodesource. Visit the Node.js website for further documentation.
The https://nodejs.org/en/ website offers built-in binaries for Windows, Mac OS X, Linux, and Solaris. We can simply go to the website, click on the install button, and run the installer. For systems with package managers, such as the ones we've just discussed, it's preferable to use the package management system. That's because you'll find it easier to stay up-to-date with the latest version. Some will prefer to install a binary.
Simply go to https://nodejs.org/en/ and you'll see something like the following screenshot. Click on the DOWNLOADS link in the header to look at all possible downloads:
For Mac OS X, the installer is a PKG
file giving the typical installation process. For Windows, the installer simply takes you through the typical Install Wizard process.
Once finished with the installer, you have a command-line tool with which you can run Node.js programs.