See the docs for the update
command:
npm update [-g] [<pkg>...]
This command will update all the packages listed to the latest version (specified by the tag config), respecting semver.
Additionally, see the documentation on Node.js and NPM installation and Upgrading NPM.
The following original answer is from the old FAQ that no longer exists, but should work for Linux and Mac:
How do I update npm?
npm install -g npm
Please note that this command will remove your current version of npm. Make sure to use sudo npm install -g npm
if on a Mac.
You can also update all outdated local packages by doing npm update
without any arguments, or global packages by doing npm update -g
.
Occasionally, the version of npm will progress such that the current version cannot be properly installed with the version that you have installed already. (Consider, if there is ever a bug in the update command.) In those cases, you can do this:
curl https://www.npmjs.com/install.sh | sh
To update Node.js itself, I recommend you use nvm, the Node Version Manager.
Apparently, there was a /Users/myusername/local
folder that contained a include
with node
and lib
with node
and node_modules
. How and why this was created instead of in my /usr/local
folder, I do not know.
Deleting these local references fixed the phantom v0.6.1-pre. If anyone has an explanation, I'll choose that as the correct answer.
EDIT:
You may need to do the additional instructions as well:
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
which is the equivalent of (same as above)...
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp
or (same as above) broken down...
To completely uninstall node + npm is to do the following:
- go to /usr/local/lib and delete any node and node_modules
- go to /usr/local/include and delete any node and node_modules directory
- if you installed with brew install node, then run brew uninstall node in your terminal
- check your Home directory for any local or lib or include folders, and delete any node or node_modules from there
- go to /usr/local/bin and delete any node executable
You may also need to do:
sudo rm -rf /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node.1 /usr/local/lib/dtrace/node.d
Additionally, NVM modifies the PATH variable in $HOME/.bashrc
, which must be reverted manually.
Then download nvm and follow the instructions to install node. The latest versions of node come with npm, I believe, but you can also reinstall that as well.
Best Answer
It's better to use the ppa from nodesource. They have done a great job keeping it updated and offering not only LTS but also latest versions of node available. https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
As easy as running this from your cli:
UPDATE:curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - sudo apt-get install -y nodejs
The reason WHY the package manager has old versions of the binaries is due to the fact it takes time for the maintainers of the provided packages to properly build and test new ones with updated versions.
The good thing is that you can consume and install packages from other repositories (ppa).