npm command not found after restart - macos

The npm command keeps becoming unrecognised after a computer restart:
-bash: npm: command not found
The node command still works fine, it's just npm that's not working. I have to reinstall Node.js from the main site to get it working again.
~/bin is added to my $PATH in my .bash_profile with:
export PATH="$HOME/bin:$PATH"
Edit: I'm also using the full mathiasbynens/dotfiles which manages its own version, I wonder if there's a conflict here.

According to nvm readme file, try to run this once:
nvm alias default stable
This will set a default Node version to be used in any new shell.

I have no explanation, but a few pointers:
As #LaurentPerrin states, node (via its official installer package) installs to /usr/local/bin.
(Why do you mention ~/bin?)
Note that different rules apply if you use user-level installs via node.js version manager nvm, in which case [symlinks to] executables are placed in ~/.nvm/v{version}/bin
Thus, the node executable should be /usr/local/bin/node.
Is this (only) what you see when you run which -a node?
The node executable is placed directly in /usr/local/bin, whereas npm is merely a symlink that points to /usr/local/lib/node_modules/npm/bin/npm-cli.js, which is an executable node script with shebang line #!/usr/bin/env node.
When you run
ls -l /usr/local/bin/npm
you should see something like
lrwxr-xr-x 1 root wheel 38 Dec 13 11:52 /usr/local/bin/npm -> \
../lib/node_modules/npm/bin/npm-cli.js
See if the symlink exists and points to the right file.
If that still doesn't work, try to invoke npm-cli.js directly and see what happens (this should show npm's command-line help):
/usr/local/lib/node_modules/npm/bin/npm-cli.js help

On OSX, node is installed to /usr/local/bin, which needs to be in your path. Edit /edit/paths as root (sudo nano /etc/paths) and make sure it is on the first line. It should look like this:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
Then you can force bash to refresh paths by running: source /etc/profile.

I was having the same problem (on OSX). Not sure if this is the solution for you, but I ended up finding npm here:
.nvm/v0.10.22/bin
or, based on your version
.nvm/v0.10.21/bin
Then I just printed my working directory and added that to my path. So for me, when I opened terminal:
cd .nvm/v0.10.22/bin
pwd
>> /path/to/.nvm/v0.10.22/bin
Hope that helps.

I use nvm to install node.js. I solve it by adding $HOME/.nvm/v0.10.25/bin to $PATH. So the problem is that the path can not be found.

I have the same problem. My solution is use sudo .... My guess this is because of the permission problem.

Related

linuxbrew/lib/ld.so: bad ELF interpreter: No such file or directory

I am having a problem about linuxbrew.
bash: /lustre7/home/lustre4/user1/applications/bin/cut: /lustre7/home/lustre4/user1/.linuxbrew/lib/ld.so: bad ELF interpreter: No such file or directory
I tried to uninstall linuxbrew using instructions at its website, but somehow it didn't work (because of sudo requirements).
there is linuxbrew directory but I can't remove when I type rm -r linuxbrew it says;
-bash: /lustre7/home/lustre4/user1/applications/bin/rm: /lustre7/home/lustre4/user1/.linuxbrew/lib/ld.so: bad ELF interpreter: No such file or directory
When I tried to install homebrew it says your CPU is not supported. (I tried this before and it worked, but now it is not working.)
I want to solve this problem but I couldn't find any solution. I am not able to run sudo and yum commands because I am not root. I am a user at a linux cluster.
OK. I finally was able to solve this issue.
I am wring in case someone else may have the same issue.
First, this was related to a bash problem. I recently installed a tool that put some variables to both bashrc and bash_profile and altered path of bin directory.
I wasn't able to use system commands such as rm, ls, cat etc. and I wasn't able to run system ruby. Paths of all commands and ruby were in my bin directory under my application directory.
What I did is;
I edited my bash_profile by cancelling the new path that caused conflict between bash_profile and bashrc. This enabled me run system commands.
I uninstalled linuxbrew as described in its website.
I removed linuxbrew from my home directory, and cancelled its path in bash_profile (comment out).
I installed homebrew again and put its path to my bashrc.
Now it is working.
I could uninstall linuxbrew using the procedure I described in here:
How to completely uninstall brew and re-install brew in ubuntu 19.04
-> In short, I just replaced install.sh by uninstall.sh and it worked...
$/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"

Why doesn't zsh recognize command from globally installed npm package?

After installing oh-my-zsh and reinstalling node and npm again, I install npm-check-updates globally and try to call 'ncu' (the npm-check-updates command). However, I get an error: zsh:
command not found: ncu. Does anyone know how to fix this?
I have corrected this problem with the following instructions:
sudo npm install -g npm-check-updates
Make sure the 'ncu' package can be found in the $PATH environment variable. Try this, to find where 'ncu' is supposed to be installed:
which ncu
If it still gives you trouble, try to see if it's in /usr/bin, $HOME/npm/bin, /usr/local/lib or /usr/sbin, and check that your $PATH environment variable contains a way to 'ncu'. Your $PATH environment variable, which can be found in
$HOME/.bashrc (Linux)
$HOME/.bash_profile (MacOS)
should look something like this:
export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/npm/bin
After an install you can run rehash so zsh will analyse what new executables are available on $PATH.
Not sure if that would fix the problem, I know it fixes the missing tab completion entry after install.
FYI I am using a OSX.
The problem was that my export path in my .zshrc was wrong.
This was what it was previously:
export PATH=$HOME/bin:/usr/local/bin:$PATH.
Notice there is nothing pointing at npm or any of the packages I installed globally.
For anyone who has this problem in the future...
Ensure that npm is installed and that you can still run npm commands (if not uninstall then install npm). Then run npm -g list --depth 0 to list all your global packages.
Go into your home folder and press ⌘+Shift+. (shows all hidden files/folders), there should be a .npm folder there, ensure the packages in the list you obtained in the previous step matches what's in the bin folder.
Edit your export PATH string accordingly:
export PATH=$HOME/bin:/usr/local/bin:**$HOME/.npm/bin**:$PATH.
This worked for me!

bash node command :no such file or directory

I have uninstalled (manually) all files related to node, npm, nvm on my MacOs as I would like to start managing everything through homebrew.
After uninstalling everything, and installing node with brew install nod -g, I ran node versionin my terminal to have the following error thrown at me:
-bash: /Users/{username}/.nvm/versions/node/v10.1.0/bin/node: No such file or directory
I am sure it has to do with a symlink somewhere that I should remove/edit, but I really have no clue where to find this and how to modify it.
Assistance would be appreciated :)
solved by adding the following to .bash-profile:
# Node path
export NODE_PATH="/usr/local/lib/node_modules"

zsh command not found, likely path issue

I recently switched to zsh from bash and couldn't install any npm bundles. I found some stack overflows telling me to reset the path in my zsh profile, which I did. Now I can't execute any commands, including bundle install.
Things I've tried:
PATH=/usr/bin:/bin:/usr/sbin:/sbin
export path
from the command line
Modifying ~/.zshrc to add
PATH=/usr/bin:/bin:/usr/sbin:/sbin
export PATH
, then saving and restarting iTerm.
When I echo $PATH, this is what I get: /usr/bin:/bin:/usr/sbin:/sbin
Restarting my terminal after each change, I still get: zsh: command not found: bundle
Help would be greatly appreciated!
UPDATE: I tried switching to another computer and cloning the repo down and am getting the same error when I try to bundle install. If I switch to another repo on the other computer (where I didn't mess with the path), bundle install works. On my initial computer (with the path edits), none of the repos allow bundle install.
Do you know where is your bundle program (you can use locate or find) ? It can be in another directory that is not in your path. For example, it can be in /usr/local/bin so you should add this path to your $PATH.

firebase-tools "-bash: firebase: command not found"

Excited that Firebase's hosting is now out of beta. Trying to get going with with the firebase-tools package and I've successfully installed it:
npm install -g firebase-tools
Trying to run any tool fails with
-bash: firebase: command not found
I've tried putting the following command in my .bash_profile without any luck
export PATH=/usr/local/share/npm/bin:$PATH
Any ideas? Pretty new to the command line in general.
Thanks!
Run code below with terminal,
alias firebase="`npm config get prefix`/bin/firebase"
Installing firebase-tools globally did the trick for me :
npm install -g firebase-tools
You should add the npm bin folder to your bash PATH variable. To do that, run:
npm get prefix
And it should output something like /home/your-username/npm-global or /home/your-username/npm-packages.
Then in your ~/.bashrc or ~/.bash_profile (if you're in a Mac) file, add:
export PATH="/home/your-username/npm-global/bin:$PATH" # Add npm bin PATH
Note the "/bin" after the npm get prefix result.
#mklement0 That answer looks good, but I'm worried it will be intimidating to someone who is so new to the command line. So I'm going to cherry-pick the most relevant piece of it.
#cienki Run this command to see what you should be putting in that PATH prefix in your .bash_profile file:
npm get prefix
by chance if you are using macOS with m1 chip
arch -x86_64 npm i -g firebase-tools
assuming that you haven't set the PATH
export PATH="`npm config get prefix`/bin:$PATH"
That's all and enjoy
On macOS: Use
curl -sL firebase.tools | upgrade=true bash
It worked for me
firebase -V
Using Windows 10, Bash
This worked for me:
npm get prefix // to find Path which for me it was C:\Users\User\AppData\Roaming\npm
search "Environment Variables" which located in "System Properties".
Under "System Variables", find the PATH variable, select it, and click "Edit". Click "New" and add the path found with the "npm get prefix" command earlier (which was for me C:\Users\User\AppData\Roaming\npm)
Then click "Ok"
Restart Bash
firebase --version //to check firebase version
Bruno's answer did the trick, I only needed to add a dot at npm-global in Ubuntu in .bashrc:
export PATH="/home/your-username/.npm-global/bin:$PATH" # Add npm bin PATH
Below command works for me on terminal
curl -sL firebase.tools | upgrade=true bash
This command install firebase tool for me
After installing:
$ npm install -g firebase-tools
$ firebase init
-bash: firebase: command not found
"If you are getting the above output then follow the below steps:"
For Windows Users:
type this cmd :
$ npm get prefix
C:\Users\Jeet\AppData\Roaming\npm [this is the location]
Now you have to set in enviorenment variable -> (windows+r) -> sysdm.cpl -> Advanced(tab) -> Environment Variables
-> under the System Variables -> click on path -> edit -> C:\Users\Jeet\AppData\Roaming\npm [paste] the above location -> apply - ok - ok.
Restart your bash terminal
Thanks!!!
For Mac OS Sierra:
$ sudo npm install -g firebase-tools
To stop other Node process use $ ps aux | grep node
If needed to upgrade or install emulator - $ npm install -g #google-cloud/functions-emulator
Ready to go $ firebase --version
For anyone using MacOS Catalina 10.15.2 getting the bash PATH variable fixed the issue for me.
Run:
npm get prefix
Then run:
export PATH=/Users/userid/.npm-global/bin:$PATH
Note: I recently upgraded from my old High Sierra MacBook Pro, and was confused as well.
For anyone using nvm the error could arise because you are on a different nvm version than you were on when you first installed firebase tools globally. That's what it was for me. When I restarted webstorm nvm switched to a different version.
Run nvm list to check the version you are on and run nvm use x.x.x to switch to the right version where you installed firebase tools originally.
This worked for me on Mac (same thing the others have been posting above, just for Mac):
go to your home folder in Finder (named after your user name, in my case "macbook")
press cmd+shift+dot (will reveal hidden files)
go the .npm-global/bin folder and copy its path (Finder menu -> View -> Show Path Bar, right click on the bin folder in the path bar -> "Copy 'bin' as Pathname")
open Terminal (by default the home folder) and go nano ~/.bash_profile
at the top of the file add export PATH="<cmd+v>:$PATH" (will look similar to this: export PATH="/Users/macbook/.npm-global/bin:$PATH")
save .bash_profile changes and restart Terminal, firebase command should work now
if you installing firebase-tools using
yarn global add firebase-tools
i got same error then i got answer and execute this
export PATH="$(yarn global bin):$PATH"
and then i can do firebase login pretty well
I am on Linux and installing the package with admin privileges resolved the problem:
sudo npm i -g firebase-tools
Simply reinstall node.js. This worked for me and fire command was recognized.
You forgot sudo type this
sudo npm install -g firebase-tools
problem solved.
I know most answers work for all generic 'command not found' errors. Basically by manually setting PATH variable but there's an easier way for this specific problem relating 'firebase command not found':
Try this cURL command and it will fix this issue for good and will minimise any user errors.
Install the Firebase CLI using the automatic install script
Run the following cURL command (Mac or Windows):
curl -sL https://firebase.tools | bash
Source: https://firebase.google.com/docs/cli#install-cli-windows, https://firebase.google.com/docs/cli#install-cli-mac-linux
This is for updated mac mac Os Catalina(10.15.1+) & on zsh.
Go to Terminal (vim .zprofile)
add this export PATH="/Users/Your Username/.npm-global/bin:$PATH"
Works for me!
Faced the same issue, am a newbie backend guy.
Used npm install firebase-tools
It doesn't install and you can't run.
I tried looking at the forums and here's what worked for me:
sudo npm install -g firebase-tools.
Then it asks for Permissions when you firebase login.
Am using Ubuntu.
After trying pretty much everything, only one worked for me (I'm on MacOs Catalina):
Try the following in your terminal:
curl -sL https://firebase.tools | bash
This will check the OS of your machine and then install everything else automatically and properly.
The command is from the official Firebase Documentation.
https://stackoverflow.com/a/60474459/1245341
After installing
$ npm install -g firebase-tools
Note the directory where it istalled What I did was locate the directory where firebase was installed. In my case C:\usr\local then I copied the three firebase files. I also went into the node_modules folder and copied the firebase tools folder. Then I went to my app directory in file manager and pasted the firebase files, then created a new node_modules folder and pasted the firebase-tools folder.
Now go to your cmd and run
$ firebase init
It should work
I tried a lot of things from here and from other forums, but what ended up working for me (and this is more of a work-around) was to download the binary and then open it and it set up all the firebase stuff for me.
However, I found that if I moved it after opening it once, it did not work. So first move it to wherever you want to leave it and then run the .exe.
This allowed me to skip configuring the PATH variable which was nice.
I'm on a Windows 10 Pro Education. Hope this helps someone who has a similar struggle.
Adding to Durul Dalkanat's answer,
Assuming you have executed npm install firebase-tools -g
Firstly get the output of the command of npm get prefix.
Open .bashrc file which is in the home directory and add alias <output of npm get prefix>/bin/firebase at the end of the file.
Run source .bashrc in the home directory.
Enjoy!
The alias of firebase will be the actual firebase path in the main system and this solution should work flawlessly.
if you're windows 8 user, one possible solution is to put the PATH in environment variables manualy...
On the Windows desktop, right-click My Computer.
In the pop-up menu, click Properties.
In the System Properties window, click the Advanced tab, and then click Environment Variables.
In the System Variables window, highlight Path, and click Edit.
In the Edit System Variables window, insert the cursor at the end of the Variable value field.
If the last character is not a semi-colon (;), add one.
After the final semi-colon, type the full path to the file you want to find.
For me it was: C:\Users\ 'username' \AppData\Roaming\npm
To get your path put this string in you command line:
$ npm get prefix
Click OK in each open window
I tried all the answers above, other SO answers, and GitHub answers but nothing worked. The only thing that worked for me was to save whatever was inside my index.js file temporarily somewhere else, delete the entire cloud functions folder, then reinstall and start everything from the very beginning.
After many hours trying everything the only thing what helped (on windows) was downloading and installing node again.
I found a solution.
npm i express firebase-tools
If you are admin on your PC, installing firebase and firebase-tools with -g flag should resolve the issue (the path will added to the global PATH variable) but if you are an admin, you may have to add that path yourself.
Seeking help from one of the top answer, issue this command will return the path where firebase is installed
npm config get prefix /bin/firebase
In my case the following is returned.
C:\Users\*user_name*\AppData\Roaming\npm
Copy that path (from first line) and visit this page on how to update path variable (Window + x then visit systems > Advance Settings). Here add a new entry in path and past that path there. Firebase command should work from command prompt every time without the use of alias required.

Resources