I’ve learned a few tricks about installing Node.js that I thought I’d share. Nothing in here is hard and you’ve got a fighting chance of getting this right on your own with no help from me, but I did learn a few things the hard way and felt I should share them.
I’m going to be covering installation for Windows, Mac OS and Ubuntu Server (or any Ubuntu shell environment).
First, decide how you want to install. The decision criteria and process will differ based on your platform:
- Use the installer package from http://nodejs.org/
- If you can’t use that, then there is a Windows binary that you can use. Simply download it and run it. You’ll have to add it to your path and deal with npm. I won’t help you with this, but I figured it out and I bet you can too, if you want to. However, I recommend the installer package if you can possibly use it.
- During the installation, one of the default options is to install npm and another is to add node to your path. Do this!
- Now, when it’s time to use Node.js, in your start menu you have a new folder called Node.js and in this folder is a “Node.js command prompt.” Use this whenever you need to use the command line utilities such as npm or commands that come from globally installed modules.
- You’re done! Test it by opening your Node.js command prompt and run
npm ls -g. You should see that you have an empty list, no modules installed globally.
- Choose between installing via the Nodejs.org installer or homebrew.
- Homebrew is what I prefer but the installation has a couple extra steps. The benefits are: You can install global modules without needing to use sudo and you can easily update your node.js using homebrew. The disadvantage is that you need to install homebrew which requires the Xcode command line tools.
- Nodejs.org installer is quick and easy to download and install. It won’t auto-update, which can be a blessing or a curse. (sometimes upgrades change behavior and your apps or utilities will be incompatible with the new version) If you go this route, follow similar instructions to those of Windows above, the rest of these steps will discuss homebrew.
- Install Xcode from the Mac app store
- Once Xcode installs, open it and go to preferences and choose the download tab.
- Install the command line tools. This may require you to log in or create a free Apple developer account
- Visit http://mxcl.github.io/homebrew/ and follow the instructions for installing homebrew (scroll down, you’ll see it)
- From a terminal, install Node.js with this command: brew install nodejs then install npm the same way, brew install npm.
- You’re done! Test it from your terminal by typing,
npm ls -g, you should see an empty list, meaning you have no globally installed modules
Ubuntu command line:
- Choose between using the Ubuntu repo’s Node.js or a repo provided by the Node.js developers
- I strongly suggest using the Node.js developers repo. You’ll get updates and have a recent version of Node on your computer
- If you feel you’ll get better OS support or you depend on a software package that relies on the Ubuntu’s repo’s version of Node then use the package from the Ubuntu repositories. Simply do:
sudo apt-get install nodejsand you’re done. The rest of these instructions will focus on using the Nodejs developer’s repos
- Visit the instructions to install the PPA for Node.js. A PPA is an add-on software repository that makes it easy to install 3rd party tools.
- You’re done! Test it from your terminal by typing
npm ls -g. You should see an empty list, meaning you have no globally installed modules.
That is it. You now have Nodejs installed and you know how to use npm. You’re ready to take on the Node world!