NPM commands not working, can't uninstall it or node - node.js

Recently I was trying to add a new dependency to my project using npm, but when I ran npm install, nothing happened. It just returned me straight back to the command line. I tried a few more npm commands like npm -v, but none of them did anything and all of them returned me back to the command line. I tried using sudo apt --reinstall install npm, didn't fix it. I tried to remove and install using sudo apt --purge remove npm, still didn't fix. I also tried uninstalling nodejs as well, but none of these things did anything to fix the issue. All npm commands just return back to the command line and do nothing, not even "command not found." One strange thing I did notice happening was that even when I restarted after uninstalling node and npm, node -v still gave the version of node I had installed. Does anyone have any idea what's going on here? (Operating system is Ubuntu 18.04)

The issue stems from the fact that my active node version was installed using n and not sudo apt install, and for whatever reason, they are in separate locations and don't like to cooperate. This led to me messing around with the PATH variable, and eventually figuring how to get the node and npm from n to uninstall. Then I just reinstalled using n and everything worked fine.

Related

Homebrew/Node.js showing up though not installed

When I do find . -name "node*" from my root directory, I get:
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node_exporter.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nodeenv.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node-sass.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#14.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#10.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nodebrew.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#12.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nodenv.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#16.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node-build.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#18.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/nodejs
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/node#19
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/node.js
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/nodeclipse.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/nodebox.rb
./usr/local/Homebrew/Library/Homebrew/rubocops/cask/extend/node.rb
./usr/local/Homebrew/Library/Homebrew/test/language/node_spec.rb
./usr/local/Homebrew/Library/Homebrew/language/node.rb
but brew ls doesn't show node and node -v and npm show that the commands are not installed on PATH? What's going on here?
I went through the process of
I went through the process of removing all traces of Node and npm from my own installation as npm was corrupted (was mishandling vulnerabilities), and now want to install it using brew, or in some other way so all the errors with npm when attempting to npm install don't occur. Why does brew have node installed even though I didn't install it?
Those files are not NodeJS itself, but are the instructions that tell Homebrew how to install NodeJS. You can remove those formula (along with any others that are not being used) with brew cleanup.
Edit: You cannot actually remove the formulae since those are needed if you were to install it at a later point.

Nvm and Node keep going missing upon closing terminal

Hoping you can help me figure out this issue!
I just bought a new MacBook and was getting my development environment set up today. I installed XCode, Brew, NVM, and Git. When I installed Git, I had to change it so it was the first in the path so I could avoid using Apple Git, and I think that severely messed things up.
For some reason, nvm was not showing when I was running:
nvm ls or nvm ls-remote
Yet when I told brew to install nvm, it said it was already installed. OK. Eventually was able to get it sorted out and install node and such.
Fast forward to now, I went to run node in the terminal. Node was not found. Did some research and found that I should not install nvm with homebrew, so I did brew uninstall nvm and brew cleanup and then installed through the recommend github repository.
I ran the necessary commands and added to my PATH, and when I ran command -v nvm, nvm was returned. GREAT. Then I ran the other commands to install Node and I was able to use it, until I closed the terminal.
Now when I reopen the terminal and run node, it returns command not found. Command -v nvm does not return anything too.
Please help - it's been such a headache and I can't seem to figure out whats going on. Every solution I'm finding on Stack Overflow works until I close the terminal.
I was able to figure it out. The command all NVM guides tell you to run in order to start running node was not properly added to .bashrc.
Use these as a reference if you have the same issue as me:
https://itnext.io/nvm-the-easiest-way-to-switch-node-js-environments-on-your-machine-in-a-flash-17babb7d5f1b
.bashrc: Permission denied

npm not compatible with node v12.5 on ubuntu 16.04

I tried updating to v12.5. I was using node version 8 before this. When I installed node v12.5 npm stopped working.
Whenever i try installing any package with npm. It shows this error.
I tried deleting node through different sources. But, it did not work.
I also tried reading different articles like these
https://tecadmin.net/install-latest-nodejs-npm-on-ubuntu/
https://websiteforstudents.com/install-the-latest-node-js-and-nmp-packages-on-ubuntu-16-04-18-04-lts/
https://www.rosehosting.com/blog/how-to-install-node-js-on-ubuntu-16-04/
I almost tried all the sources available on web.
I tried
sudo apt purge node
sudo apt autoremove
and some similar commands. But, it did not work.
Whenever i type node -v. it still shows me 12.5
and when i type npm -v. it shows me 5.5.1.
How do i either remove node completely?
or
install specific version of node?
or upgrade npm to version 8.x
How do I solve the problem?
I cannot even install anything, it shows this error even after installing some other packages.
how do i solve it?
EDIT:
I found the solution...
its basically using nvm to install different versions of node in your machine.
and setting default version for your machine using nvm

Global npm installs break after restarting terminal

I recently installed node using nvm and had no problems initially with installing globally packages with npm. But then I found that if I close the terminal in which I originally installed the package, I will get "command not found" when attempting to use it.
For example, browser-sync. I closed the terminal after finding that it worked properly. When I opened it up later to continue working on the project I need it for, it turns out that now I get "command not found" in every directory despite installing it globally.
I am running Linux Mint Cinammon 17.3 with the latest version of node and npm.
Any help for this?
I've since solved this problem by:
Completely uninstalling nvm and node.
Reinstalling node using apt-get
Changing npm config prefix to /usr/local
Correctly setting npm permissions
For some reason despite multiple uninstalls/reinstalls and playing with permissions before, it wouldn't work until I deleted all the folders created by node or npm before reinstallment. Weird.

NPM appears to do nothing on Linux Mint 15

searched, and did not see this specific problem.
Trying to get a MEAN stack built on my Linux Mint machine, and bumping into a bit of an unusual issue.
Got MongoDB installed, and finally got it running correctly (none of the instructions ANYWHERE mentioned having to create the /data/db/ directory and set permissions, go figure).... it works now.
Got NodeJS installed, and it appears to work correctly.
I had been told (apparently incorrectly) that NPM installs right alongside Node, with:
sudo apt-get install nodejs
but:
$ npm
bash: /usr/bin/npm: No such file or directory
So I go ahead and install NPM separately.
$ sudo apt-get install npm
Seems to work, so far, no errors, and it looks like it is pulling down the NPM package and installing it...
$ nodejs -v
v0.10.21
$ npm -v
$
?? It simply fails to respond without any error... so I try:
$ npm install grunt -g --save-dev
$
Same completely silent failure... in fact, NOTHING I could do gets a response out of NPM.
Looked all over the web, and saw nothing similar anywhere... found out that NPM holds its cache files in ~/.npm and noticed that this folder didn't exist (kinda like the mongo issue above), so I created it, and set permissions to 7777... still nothing.
Purged and re-installed both node and npm, tried installing them both together and separately (yes, desperation)... still no love.
WTF am I doing wrong?
I would love, eventually, to have a nice development environment setup, hopefully with Cloud9 as a local IDE.... but already pulling my hair out.
=========================================================================================
OK, after a few more headaches, this is up and built now... thank you all.
Would love to mark both as answers, but it won't let me.
npm does come with node. Where is apt-get pulling it from? I install the Mac OS X packages on my Mac for development and npm does in fact come with it. I compile from source on my CentOS server and npm comes with it.
Your package provider may be providing them separately as a (in)convenience to you.
As for why your npm command does not work after installation, I can't say for sure, but I am suspicious of your use of --save-dev and -g together.
-g means to install globally, which means 2 things:
It will be installed outside of your npm package's structure into a system location like /usr/bin or /usr/local/bin
It requires root access to install. Did you use sudo to run it with root access?
Both of those requirements conflict with --save-dev which records the package as a dependency in your package.json file so that future npm install commands will install that package within the project space.
That said, I happen to know a lot about grunt. It has 2 parts, a globally installed tool and the package-specific tool. The correct way to install it is:
$ [sudo] npm install -g grunt-cli
$ npm install grunt --save-dev
This will install the grunt-cli package into a system location guaranteed to be in the $PATH, which turns around and looks for a package-specific grunt installed which is not system-wide.
When installing nodejs with npm, this one-liner worked for me.
sudo apt-get install nodejs nodejs-dev npm
I don't believe npm comes with the nodejs installation in the apt repo. Try to install npm separately using the following tutorial http://www.giantflyingsaucer.com/blog/?p=1688 'To install NPM ....'
====== Edit ====
node and npm IS separate. Follow the official wiki and everything should be fine

Resources