Unable to upgrade npm from 1.4.28 to latest (2.2) - node.js

I'm using stable version of node on Ubuntu 14.04. (installed via PPA) When I was trying to upgrade some packages like yo, I got the error below:
npm ERR! notsup Unsupported
npm ERR! notsup Not compatible with your version of node/npm: yo#1.4.2
npm ERR! notsup Required: {"node":">=0.10.0","npm":">=2.1.0"}
npm ERR! notsup Actual: {"npm":"1.4.28","node":"0.10.35"}
npm ERR! System Linux 3.13.0-32-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "update" "-g"
npm ERR! cwd /home/ekrem
npm ERR! node -v v0.10.35
npm ERR! npm -v 1.4.28
npm ERR! code ENOTSUP
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/ekrem/npm-debug.log
npm ERR! not ok code 0
When I hit (sudo) npm update -g npm, here's the result I got:
npm#2.1.3 /home/ekrem/.node/lib/node_modules/ionic/node_modules/npm
After hitting npm -v
1.4.28
I've also cleared all files under ~/.npm, cleared cache, reinstall components I needed but nothing changes. In addition;
➜ ~ which node
/usr/bin/node
➜ ~ which npm
/usr/bin/npm
➜ ~ less ~/.npmrc
prefix = ~/.node
I've checked similar issues on the net but there's nothing close to mine.
UPDATE:
I've removed nodejs; cleared files under ~/.node & ~/.npm (as #johns has suggested) installed using first method of the instructions here. Here are updated outputs:
➜ node -v
v0.10.35
➜ npm -v
1.4.28
➜ which node
/home/ekrem/local/bin/node
➜ which npm
/home/ekrem/local/bin/npm
➜ npm update -g npm
# returns nothing
➜ ~ npm config get prefix
/home/ekrem/.node

I was facing a similar issue and found this post. The way I got npm to work after several tries is to remove all the npm 'node_module' folders and delete any npm config files particularly the .npmrc file in your home directory.
Then I ran 'sudo apt-get purge nodejs'.
I went to the installer and reinstalled nodejs using the following:
'curl https://npmjs.org/install.sh | sh'
then ran:
sudo apt-get install nodejs
Finally I ran:
npm update -g npm
There were issues posted about a bug in that 'update' function, but it seemed to work for me and I got from 1.4 to 2.7.
I hope this saves someone some time.

This solution worked for me
navigate to C:\Program Files (x86)\nodejs with cmd.exe and then run the installation without -g:
npm install npm

In my case I had to do the following steps to go from npm#1.4.28 to npm#3.2.0 (currently the latest):
curl -L https://www.npmjs.org/install.sh | sudo sh
This line may trigger some errors like:
Error: EACCES, mkdir '/usr/lib/node_modules/npm'
If so, simply run:
sudo rm -rf /usr/lib/node_modules/npm (or the specified directory display in the error)
From there:
sudo npm install -g npm#3.0-latest
And now the
npm -v
successfully display a beautiful: 3.2.0

There are a lot of comments out there about "npm update -g" being broken and to not use it for now:
https://github.com/npm/npm/issues/6247
I'd trying resetting or reinstalling npm and then go from there - a fresh reinstall of npm should be relatively painless and fix things:
https://github.com/npm/npm/wiki/Troubleshooting#if-your-npm-is-broken

Similar answer to #ThinkBonobo, but all I had to do was run the update straight from npmjs.org. From a freshly provisioned instance:
$curl -sL https://deb.nodesource.com/setup | sudo bash -
$sudo apt-get install nodejs
$npm -v
1.4.28
$curl -L https://npmjs.org/install.sh | sudo sh
$npm -v
2.7.3
No other steps were requried.

Related

How to fix this Error -npm

I tried to install npm and I got the following error.
I already removed npm and reinstall it again, but I again got the following error:
npm ERR! Linux 4.15.0-30-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! vx-leave-system#0.0.1 start: `node ./tools/server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vx-leave-system#0.0.1 start script 'node ./tools/server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the vx-leave-system package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./tools/server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs vx-leave-system
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls vx-leave-system
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/seelan/Documents/vx-leave-system/npm-debug.log
How can I fix this?
On ubuntu 18.04 following steps saved me
To remove the distro-stable version, type the following:
sudo apt remove nodejs
This command will remove the package and retain the configuration files.
sudo apt purge nodejs
As a final step, you can remove any unused packages that were automatically installed with the removed package:
sudo apt autoremove
Refresh your local package index by typing:
sudo apt update
Enable the NodeSource repository by running the following command
(optinal) If you need to install another version, for example 14.x, just change setup_12.x with setup_14.x
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
Once the NodeSource repository is enabled, install Node.js and npm by typing:
sudo apt install nodejs
Verify that the Node.js and npm were successfully installed by printing their versions:
node --version (v12.18.4)
npm --version (6.14.6)
It seems to me that you're running a newer version of Node, but an outdated version of NPM.
You can do either of the following:
Try the latest stable version of NPM:
You can upgrade to the latest version of npm using: npm install -g npm#latest
Uninstall Node form your machine completely, go to their website and install the latest stable Node version. NPM comes with it.
I faced this issue too today and the problem was caused by an upgrade in my node and npm version. Guess my project dependencies were still running on older versions of node and npm
I fixed it by deleting the node_modules folder and run
npm install
I hope this helps
This looks like a permissions issue in your home directory. To reclaim ownership of the .npm directory execute:
sudo chown -R $(whoami) ~/.npm
Check the updates of dependencies
npm outdate
Run the next command to update dependencies
npm update
Remove the path folder directory C:\Users\ACER\AppData\Local**\npm-cache_logs\2021-12-29T13_41_22_984Z-debug-0.log**
and then run this command in your CLI npm install -g npm#latest
this works with you

Different version of npm when using sudo?

when I tried to update npm, I found that command returns Permission deny:
npm install npm -g
Then I tried:
sudo npm install npm -g
Then npm has been updated, but when I tried npm -v and sudo npm -v, they show different version:
npm -v //3.10.10
sudo npm -v //5.1.0
How can I make them always in the same version? It also happened on command 'node -v'. I am using fedora.

Getting npm: command not found. How do I reinstall NPM when Node is already installed? Where did NPM go?

I'm starting Learn to Build Modern Web Apps with the AngularJS Tutorial and running into issues very early.
I have node installed:
/path/ang-news node -v
v0.10.26
I was using NPM earlier but was running into trouble with Yeoman. I've repeated these steps a while back but Grunt stopped working so I started fresh.
I ran:
$ sudo npm install -g generator-angular
and all the dependencies were installing until I received:
npm WARN package.json mongo#0.1.0 No repository field.
npm ERR! peerinvalid The package generator-karma does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer generator-angular#0.9.1 wants generator-karma#>=0.8.2
I then tried updating:
$ npm update -g
I should have run this as an administrator. I received tons of error messages, this seemed most pertinent:
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 13.1.0
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "update" "-g"
npm ERR! cwd /path/ang-news
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! not ok code 0
Then I tried uninstalling generator-karma and starting fresh:
$ sudo npm uninstall -g generator-karma
but received:
sudo: npm: command not found
$ npm -v
-bash: /usr/local/bin/npm: No such file or directory
My first question is: Why did NPM suddenly disappear?
[EDIT: Kudos to #try-catch-finally to pointing out the havoc that ensues when switching between normal user and sudo when issuing commands. It turns out that I messed up my user environment and NPM was no longer installed.]
My understanding is that NPM is installed when you install Node, so my second question is: How do I reinstall just NPM? I'd prefer not to have to reinstall Node from the beginning.
[EDIT: Kudos to #hawk and #try-catch-finally - it doesn't appear that installing NPM alone is an option, but there are easy ways to reinstall both.]
If you have a working node, you can re-install npm
curl -L https://npmjs.org/install.sh | sudo sh
Unfortunately npm update -g does not do what anybody expects. Fixing this is on the npm roadmap, but it's going to take a while.
You almost never need to install a package globally, unless (like generator-angular or grunt-cli) you want to use that package as a command.
Just in case you've done this with brew, I recommend this article on github. Will save you a lot of time.
https://gist.github.com/DanHerbert/9520689
Fixing npm On Mac OS X for Homebrew Users
Run the following commands to remove all existing global npm modules, uninstall node & npm, re-install node with the right defaults, install npm as its own pacakge, and configure the location for global npm modules to be installed.
rm -rf /usr/local/lib/node_modules
brew uninstall node
brew install node --without-npm
echo prefix=~/.node >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
Node and npm should be correctly installed at this point. The final step is to add ~/.node/bin to your PATH so commands you install globally are usable. I added this line to my ~/.path script, which gets run via ~/.bash_profile. Run the following line as is.
export PATH="$HOME/.node/bin:$PATH"
I met the exactly same problem after execute command to install the npm with latest version on redhat 7.1:
npm install npm#latest -g
after some tries i found the solution:
yum reinstall npm
I hope this could help redhat/centos users.

NPM install giving error installing express

When I give command npm install express it throws following error. On ubuntu machine
gaurav#gaurav-Mini-Monster:~/TestScripts$ sudo npm install -g express
npm ERR! error installing express#3.3.3 Error: Unsupported
npm ERR! error installing express#3.3.3 at checkEngine (/usr/local/lib/node_modules/npm/lib/install.js:493:14)
npm ERR! error installing express#3.3.3 at Array.0 (/usr/local/lib/node_modules/npm/node_modules/slide/lib/bind-actor.js:15:8)
npm ERR! error installing express#3.3.3 at LOOP (/usr/local/lib/node_modules/npm/node_modules/slide/lib/chain.js:15:13)
npm ERR! error installing express#3.3.3 at chain (/usr/local/lib/node_modules/npm/node_modules/slide/lib/chain.js:20:4)
npm ERR! error installing express#3.3.3 at installOne_ (/usr/local/lib/node_modules/npm/lib/install.js:470:3)
npm ERR! error installing express#3.3.3 at installOne (/usr/local/lib/node_modules/npm/lib/install.js:411:3)
npm ERR! error installing express#3.3.3 at /usr/local/lib/node_modules/npm/lib/install.js:347:9
npm ERR! error installing express#3.3.3 at /usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:54:35
npm ERR! error installing express#3.3.3 at Array.forEach (native)
npm ERR! error installing express#3.3.3 at /usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:54:11
npm ERR! error rolling back express#3.3.3 Error: UNKNOWN, Unknown error '/usr/local/lib/node_modules/express'
npm ERR! Unsupported
npm ERR! Not compatible with your version of node/npm: connect#2.8.3
npm ERR! Required: {"node":">= 0.8.0"}
npm ERR! Actual: {"npm":"1.0.106","node":"0.5.11-pre"}
npm ERR!
npm ERR! System Linux 3.2.0-48-generic-pae
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "express"
npm ERR! cwd /home/gaurav/TestScripts
npm ERR! node -v v0.5.11-pre
npm ERR! npm -v 1.0.106
npm ERR! code ENOTSUP
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/gaurav/TestScripts/npm-debug.log
npm not ok
I also tried
sudo npm install express
npm install -g express
sudo npm install -g express
Nothing works.
Node is so easy to install manually. I like doing it this way too because it's really easy to switch versions.
This is also great because you don't need to add some external package repository to apt, and you don't have to wait for those repositories to update when node releases a new version. You can get updates as soon as they're released.
# make a `~/.nodes/ folder
mkdir -p ~/.nodes && cd ~/.nodes
# download the binaries from nodejs.org
# in this case, here's the linux version
curl -O http://nodejs.org/dist/v0.10.12/node-v0.10.12-linux-x64.tar.gz
# extract
tar -xzf node-v0.10.12-linux-x64.tar.gz
# rename folder to 0.10.12
mv node-v0.10.12-linux-x64 0.10.12
# create a `current` symlink
ln -s 0.10.12 current
# prepend ~/.nodes/bin to your path
# you'll want to save this in ~/.bashrc or ~/.zshrc or something
export PATH="~/.nodes/current/bin:$PATH"
# cleanup
rm ~/.nodes/node-v0.10.12-linux-x64.tar.gz
The best part about this is you can repeat the pattern for any other version of node, change the current symlink at any time to switch which version you're running, and you're good to go
% node --version
v0.10.12
% npm --version
1.2.32
# switch versions to (e.g.) 0.10.5
% cd ~/.nodes && rm current && ln -s 0.10.5 current
% node --version
v0.10.5
% npm --version
1.2.18
Additional pointers when writing executable scripts
Make an executable file
% touch ~/somefile && chmod +x ~/someifle && nano ~/somefile
File contents
#!/usr/bin/env node
console.log(process.version);
Run it
% ./somefile
v0.10.12
You are running a much-too-old version of node and npm. You have node v0.5 which is very out of date. Upgrade to node v0.10 and things will work.
Modern node.js versions for Ubuntu are available via this PPA from Chris Lea
To install:
sudo apt-get install python-software-properties
sudo add-apt-repository --yes ppa:chris-lea/node.js
sudo apt-get install nodejs
UPDATE
It looks like your old version of node is installed at /usr/local/bin/node. The new version from the Chris Lea PPA will be at /usr/bin/node. So to verify all is well, do:
/usr/bin/npm --version #Should be approx 1.2
/usr/bin/node --version #should be approx v0.10
/usr/bin/npm install -g express
You should uninstall the local node, or fix your PATH:
export PATH=/usr/bin:$PATH

npm install error ENOTDIR

I am very new to Node.js and trying to install Flatiron using npm but it gives me an error.
sudo npm install flatiron -g
And I get -
npm http GET https://registry.npmjs.org/flatiron
npm http 304 https://registry.npmjs.org/flatiron
npm ERR! Error: ENOTDIR, mkdir '/home/siddharthsaha/tmp/npm-28554/1353323290836-0.20847953506745398'
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR! System Linux 3.2.0-24-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "flatiron" "-g"
npm ERR! cwd /home/siddharthsaha/denarit
npm ERR! node -v v0.8.14
npm ERR! npm -v 1.1.65
npm ERR! path /home/siddharthsaha/tmp/npm-28554/1353323290836-0.20847953506745398
npm ERR! code ENOTDIR
npm ERR! errno 27
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/siddharthsaha/denarit/npm-debug.log
npm ERR! not ok code 0
What is wrong here? I have no clue.
Just solved the issue. Its because there's a file called tmp in the home directory.
rm -rf ~/tmp
sudo npm cache clear
sudo npm install -g node
Also... if you are trying to install npm then the same error and solution applies - delete ~/tmp
Try
sudo mkdir -p /home/siddharthsaha/tmp
sudo npm cache clear
before starting the install script, since npm http 304 https://registry.npmjs.org/flatiron line states that this module is coming from cache. And also ENOTDIR states that there is no directory. Therefore, emptying the cache would solve your problem.
Below are the steps to install a given release from source without root
NOTE - this installs nodejs which gives you both node as well as npm,
they come together per release.
to start fresh remove prior node.js and npm installs as well as these :
sudo mv ~/.npmrc ~/.npmrc_ignore
sudo mv ~/.npm ~/.npm_ignore
sudo mv ~/tmp ~/tmp_ignore
sudo mv ~/.npm-init.js ~/.npm-init.js_ignore
to install nodejs and npm as yourself NOT root do these commands (OSX/linux) :
export NODE_PARENT=${HOME}/bin_0_10_32
mkdir ${NODE_PARENT}
download source from : http://nodejs.org/download/
cd node-v0.xxxx
./configure --prefix=${NODE_PARENT}/nodejs
make -j8
make install # IMPORTANT this is NOT using sudo
# not wanted since installing into $USER owned $NODE_PARENT
which puts it into dir defined by above --prefix
export PATH=${NODE_PARENT}/nodejs/bin:$PATH
define environment variable NODE_PATH so node can find dir for modules otherwise
npm install xxx will put newly installed module into current dir :
export NODE_PATH=${NODE_PARENT}/nodejs/lib/node_modules
when you use syntax : npm install -g some_cool_module
the -g for global installs it into dir $NODE_PATH and not your $PWD
nodejs install gives you npm as well :
ls -la ${NODE_PARENT}/nodejs/bin
Subsequent modules you install using global flag -g will automagically put
their ~binaries~ into above bin dir ... like browserify
Now put above three export xxx=yyy
commands into your ~/.bashrc or some such so your environment is setup
I direct delete the file of npm-debug.log.
then it's ok for me.

Resources