Development is picking pace, and Node.js is shipping out a new version frequently. It is nice to have the latest version at hand in your development environment to test out new features.
Install NVM, Node.js, Yarn via Homebrew. GitHub Gist: instantly share code, notes, and snippets. Homebrew, Mac系统的包管理器,用于安装NodeJS和一些其他必需的工具软件。. The command uses curl to download the Homebrew installation script from Homebrew’s Git repository on GitHub. Let’s walk through the flags that are associated with the curl command: The - f or -fail flag tells the Terminal window to give no HTML document output on server errors. Install NVM, NodeJS, Yarn via Homebrew Notice Prerequisites Getting start Part A: Install NVM and NodeJS Part B: Install Yarn and Linked nvm node to Homebrew Part C: Upgrading, To change node.js version and Re-configure Homebrew.
There are a few ways to install Node.js. One of the obvious ones is to download the installer from nodejs.org. However, you might not want to be downloading a new installer every time there's a new version out.
Here are few alternative ways to update to the latest version of Node.js on a Mac.
Nvm
Nvm is a script-based node version manager. You can install it easily with a curl and bash one-liner as described in the documentation. It's also available on Homebrew.
Assuming you have successfully installed nvm. The following will install the latest version of node.
The last option installs all global npm packages over to your new version. This way packages like mocha and node-inspector keep working.
N
N is an npm-based node version manager. You can install it by installing first some version of node and then running npm install -g n
.
Assuming you have successfully installed n. The following will install the latest version of node.
Homebrew
Homebrew is one of the two popular package managers for Mac. Assuming you have previously installed node with brew install node
. You can get up-to-date with formulae and upgrade to the latest Node.js version with the following.
MacPorts
MacPorts is the other package manager for Mac. The following will update the local ports tree to get access to updated versions. Then it will install the latest version of Node.js. This works even if you have a previous version of the package installed.
There also exists nodejs
alternative to nodejs-devel
that follows the long term support line.
If you’re looking for an easy guide to install Node.js and npm on OS X and macOS — this is it.
Before we get started, are you listening to JS Party? If not, you should be! Maybe start with our episode all about best practices for Node developers. ✊
The default method for installing Node.js is to download a pre-built installer for your platform, install it and make sure it’s on your $PATH
.
However, if you’re a Homebrew fan like me and prefer to install all of your packages with it — ensuring your packages are installed using the same commands and directories and allowing Homebrew to easily manage upgrades and updates — then this guide will help you get started.
Install Node.js and npm with Homebrew
First, install Homebrew.
Then run brew update
to make sure Homebrew is up to date.
Homebrew Nodejs Lts
As a safe measure you should run brew doctor
to make sure your system is ready to brew. Run the command below and follow any recommendations from brew doctor.
Next, add Homebrew’s location to your $PATH
in your .bash_profile
or .zshrc
file.
Homebrew Node.js Install
Next, install Node (npm will be installed with Node):
To test out your Node and npm install, try installing Grunt (you might be asked to run with sudo):
Homebrew Node.js Mac
If that worked then congratulations — you’ve installed Node.js, npm, and Grunt.
If not — retrace your steps or post a question to Stack Overflow.
Homebrew Node.js Pro
Listen to related podcasts on The Changelog
Homebrew Install Npm
Since you’re interested in Node.js, npm, and Homebrew — listen to some recent related podcasts we’ve done on those subjects.