So you have tried the official install instructions for installing NodeJs, but you are running into problems with the installation.
For the Windows platform, NodeJs allows you to choose the directory in which to install the platform, so you will not face any issues.
For Linux and Mac, there is an issue,
because the installer defaults to
which are directories that require
sudo access to write files to.
Thus, whenever you do a global installation of a node module,
it attempts to install it in a subdirectory which requires
When the NodeJs platform is installation in a directory that requires
any global installs will result in a bunch of errors of type
which you will see output to your terminal.
A rookie mistake, upon seeing these, would be to ignore them,
and simply repeat your previous global installation command,
this time with the
sudo command in front of it.
After all, after the error messages,
this is precisely what the suggested fix is.
This will appear to work at first, as the installation will succeed.
However, it sets you up for inevitable failure down the road,
as sooner or later the need to use
sudo will spread -
to pretty much all NodeJs related activities,
and you might find that unless you start your IDE using
your projects cannot build.
Now you are in over your head!
If you are the sort who is unfazed when dealing with C compilers, and are a command line whiz, then this is the option for you. Chances are, however, if you fall into this category, you would have defaulted to this route anyway - instead of getting stuck and reading this article!
If you are on Mac, and you already have homebrew installed, then you can simply do:
brew install node
… to install the latest version of NodeJs.
For everyone else, there is Node Version Manager.
In a nutshell, what NVM does is to install the NodeJs platform in a subdirectory of your user home directory, by compiling from source - taking care of all the required steps. It then sets up symbolic links and various environment variables to ensure that it can run. It also allows you to install multiple versions of NodeJs side by side, and switch between them rather effortlessly.
The main thing that we care about in all of this, however,
is simply the fact that NVM is the easiest way to install the NodeJs platform
in a directory that does not require
Project page: https://github.com/creationix/nvm
~/.bashrcfile is used instead, and would already exist by default.
bash, such as
ksh, ensure that the appropriate terminal start script contains
nvm install 0.10
nvm alias default 0.10
nvm use default
0.10, you could choose
0.12, or any specific patch number!
node: command not found
Now whenever you do a global installation,
you need not use
because NodeJs is installed in a subdirectory of your home directory,
which doesn’t require
sudo access to write files.
npm install --global npm
This should install
npm in the global
without a hitch.
If you have previously installed NodeJs using another method,
and have used
sudo npm ... commands before,
you might still run into problems,
where global installations without
sudo continue to fail.
The first action you should take, to overcome this, is to find where the previous installation was located and delete it.
The second action you should take, is to find a directory in your home directory,
.npm, and ensure that the
root user does not own any of those files.
The following command should help you with that.
sudo chown -R $( whomami ) ~/.npm
If you are using Linux or Mac, install NodeJs using NVM to save yourself from a lot of headaches!
Copyright © 2008-present Brendan Graetz