npm command not found in zsh but found in bash - bash

I installed npm with nvm and the first time it went all great, now I tried to check npm version on Mac terminal an it shows:
% npm --version
zsh: command not found: npm
But using VSCode terminal with bash, with same command, shows:
npm --version
6.14.12
Is there a chance I installed the wrong way npm or nvm? Or is this a way I can tell Mac terminal to use bash instead of zsh?

I managed to solve this issue first by executing echo $PATH in both bash and zsh the result was:
bash: /Users/myuser/.nvm/versions/node/v12.22.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
zsh: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Both paths have /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
But only bash has this: /Users/myuser/.nvm/versions/node/v12.22.1/bin:
So I needed to add that missing path to zhs path, since I didn't have a .zshrc file I needed to do:
echo 'PATH="~/.nvm/versions/node/v12.22.1/bin:$PATH"' >> ~/.zshrc
After that I do reset on terminal and verify again with echo $PATH that I have the same path on both terminals.
Finally executed the following command: source ~/.zshrc, reseted terminal again and now both bash and zhs are sync and usable.

Related

How to Fix “Command Not Found” in command line

Chances are that you might be getting the following error on your Mac, when you have been trying to run commands in the terminal
and you have already installed the commands
zsh: command not found: git
or
zsh: command not found: curl
The fix is in the answer below
Chances are that something might have gone wrong with the users $PATH on your machine or maybe the actual path where the command is has not been set.
You can just run the command below, this should fix you issue:
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
and if you feel like checking the path you can just run :
echo $PATH

zsh: command not found -- no longer have access to basic utilities and all installed softwares or packages from the terminal

Looks like I have managed to scramble my path variable when installing flutter, and now running yarn, shows zsh: command not found: yarn
This was the command I ran that I started experiencing the zsh command not found:
echo 'export PATH="$PATH:[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin >> ~/.zshrc"
I ran the code solution suggested by #devnull https://stackoverflow.com/a/18428774/1766068
PATH=/bin:/usr/bin:/usr/local/bin:${PATH}
export PATH it would work when I open a new tab, but if I should restart the terminal it no longer works.
Open your ~/.zshrc file in a text editor and remove the last line. Then logout and login again.

how to fix "bash: flutter: command not found" error?

I have been working on flutter using VScode with all environment variables set on Windows OS. Now i upgraded the flutter using "flutter upgrade" in Git Bash terminal of VScode to the stable version and now i am not able to use flutter commands in Git Bash terminal of VScode. I wonder where things could have gone wrong , how do i fix it ?
I re-verified that all my environment variables are set correctly according to official documentation. Also flutter commands are running perfectly through flutter console .
Ashish#DESKTOP-3JFCI3M MINGW64 ~/Desktop/Flutter Exercise/test_2
$ flutter doctor
bash: flutter: command not found
Edit: Made changes to the "~/.bash_profile" as mentioned by Sam , still getting the same error . Also i re-checked and the environment variables are set there already. Any ideas what i could do further to fix it ? Thanks in Advance :)
Also when executed command of step no 3. source ~/.bash_profile , output is
$ source ~/.bash_profile
bash: C:DEVLOPMENTflutterbin: command not found
bash: C:DEVLOPMENTflutterbincachedart-sdkbin: command not found```
It's possible that the environment variable, that was previously set, got cleared at some point and that's why the Flutter command is not recognized.
In any case, one way to make sure that Flutter is in your profile is to add it to your path within your ~/.bash_profile (bash profile) file. The ~/.bash_profile is a script gets executed every time you open Git Bash.
Adding Flutter to your Bash Profile
Open your ~/.bash_profile file for editing:
$ nano ~/.bash_profile
Add to the top of your ~/.bash_profile file, the following lines:
# Add Flutter to PATH
PATH=/path/to/flutter/bin:$PATH
# Add Dart to PATH
PATH=/path/to/flutter/bin/cache/dart-sdk/bin:$PATH
Replace /path/to/flutter, with the absolute path of your Flutter installation directory.
Apply the changes:
$ source ~/.bash_profile
Ensuring Git Bash is opened for non-login shells
(Credit: Charles Duffy)
$ echo "source ~/.bash_profile" >> ~/.bashrc

rbenv command not found on Mac OS

We are trying to run rbenv on El-Capitan 10.11.6. When we try to run rbenv command in the terminal we got the following error message:
command not found
We googled how to solve that issue and one possible solution is to add the "rbenv" to the system PATH, we followed the steps stated in this link. When we run the "$PATH" to check whether or not the rbenv path was added properly into the system PATH, we got the the same result:
command not found
The result of "$PATH" command is:
qwe-Mac-mini:~ amrbakri$ rbenv
-bash: rbenv: command not found
qwe-Mac-mini:~ asd$ echo $PATH
/Users/asd/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/MacGPG2/bin
Can you please tell me how to add the path of rbenv properly? And what did I do wrong in the previous steps so that I can fix it.
rbenv isn't a normal command if you've installed it correctly:
$ type rbenv
rbenv is a function
. . .
According to Homebrew on Mac OS X:
You'll only ever have to run rbenv init once.
That's a bit misleading because the result of running the command is:
$ rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"
So you need to manually add eval "$(rbenv init -)" to some file that bash will source on startup. For most people ~/.bash_profile is the right place.
I notice the commands you listed seem to be run from two different users: amrbakri and asd. Combined with the question's use of "we", I wonder if there might be a problem with the environment being set correctly for one user, but not the other. Can you try using just one user?
If you are running from a non-interactive shell (such as in a crontab), you might need to add eval "$(rbenv init -)" to the startup script.
I following the instructions about "bash" command, then do the "eval" operation.
I'm in MacOS 11.2.3, in your .bash_profile, add the two lines.
export PATH="$HOME/.rbenv/bin:$PATH"#this is the required step for my mac
eval "$(rbenv init -)"
refer: https://github.com/rbenv/rbenv#homebrew-on-mac-os-x

Command not found after npm install in zsh

I'm having some problems installing vows via npm in zsh. Here's what I get. I tried installing it with and without the -g option. Do you have any idea what's wrong here?
[❤ ~/Desktop/sauce-node-demo:master] npm install -g vows
npm http GET https://registry.npmjs.org/vows
npm http 304 https://registry.npmjs.org/vows
npm http GET https://registry.npmjs.org/eyes
npm http GET https://registry.npmjs.org/diff
npm http 304 https://registry.npmjs.org/eyes
npm http 304 https://registry.npmjs.org/diff
/usr/local/share/npm/bin/vows -> /usr/local/share/npm/lib/node_modules/vows/bin/vows
vows#0.6.4 /usr/local/share/npm/lib/node_modules/vows
├── eyes#0.1.8
└── diff#1.0.3
[❤ ~/Desktop/sauce-node-demo:master] vows
zsh: command not found: vows
add source /home/YOUUSERNAME/.bash_profile at the beginning of ~/.zshrc
And all missing commands will be detected.
For Mac users : add source /Users/YOUUSERNAME/.bash_profile
If you installed Node.js using Homebrew, npm binaries can be found in /usr/local/share/npm/bin. You should make sure this directory is in your PATH environment variable. So, in your ~/.zshrc file add export PATH=/usr/local/share/npm/bin:$PATH.
If you have added using nvm please add the following to your .zshrc file and restart the terminal since the binaries of the file are not being detected by zsh shell we specify the path
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Mac users only
assuming you installed nvm prior, and npm correctly
(step-by-step guide below on how to install it:
install nvm for Mac users
).
you need to:
Find the '.zshrc' file:
Open Terminal.
Type open ~ to access your home directory.
Press Cmd + Shift + . to show the hidden files in Finder.
Locate the .zshrc.
Edit the '.zshrc' file:
add: source /Users/_user_Name_/.bash_profile to the top of the file (where _user_Name_ stands for your user.
Save the file, and close the Terminal window.
For Mac users:
Alongside the following:
nvm, iterm2, zsh
I found using the .bashrc rather than .profile or .bash_profile caused far less issues.
Simply by adding the latter to my .zshrc file:
source $HOME/.bashrc
On Ubuntu, after installing ZSH, and prevously on the bash terminal installed Node or other packages,
First open:
nano .zshrc
And uncomment the second line:
export PATH=$HOME/bin:/usr/local/bin:$PATH
This works for me, and without writting any line, and I think this option is available on Mac too.
Go to your terminal and run: nano .zshrc
NOTE: If you don't have this file, you may create it using the 'touch' command:
touch ~/.zshrc
Paste the following anywhere below the line containing "export ZSH":
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Now simply hit ^X and you will be asked if you would like to save. Say 'yes' and hit return, then hit return again if it says you are changing a file. You may need to restart your terminal after saving.
Try using node -v as a quick test if you've installed node before.
For me the accepted answer for adding export PATH=/usr/local/share/npm/bin:$PATH to .zshrc didn't work. I tried adding the NVM_DIR as well which solved my issue.
Try vi .bashrc
You will find a line like the following. Copy it.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Paste the copied content to .zshrc file
Restart the terminal
I hope this solves your issue.
for macOS users: consider using .profile instead of .bash_profile. You may still need to manually add it to ~/.zshrc:
source $HOME/.profile
Note that there is no such file by default! Quoting slhck https://superuser.com/a/473103:
Anyway, you can simply create the file if it doesn't exist and open it in a text editor.
touch ~/.profile
open -e !$
The added value is that it feels good man to use a single file to set up the environment, regardless of the shell used. Loading a bash config file in zsh felt awkward.
Quoting an accepted answer by Cos https://stackoverflow.com/a/415444/2445063
.profile is simply the login script filename originally used by /bin/sh. bash, being generally backwards-compatible with /bin/sh, will read .profile if one exists
Following Filip Ekberg's research / opinion https://stackoverflow.com/a/415410/2445063
.profile is the equivalent of .bash_profile for the root. I think the name is changed to let other shells (csh, sh, tcsh) use it as well. (you don't need one as a user)
getting back to slhck, a note of attention regarding bash:
(…) once you create a file called ~/.bash_profile, your ~/.profile will not be read anymore.
Another thing to try and the answer for me was to uncomment the first export in ~/.zshrc:
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
I solved this by brew upgrade node
For anyone who is still having problem. Don't forget to logout and login again.
In my humble opinion, first, you have to make sure you have any kind of Node version installed. For that type:
nvm ls
And if you don't get any versions it means I was right :) Then you have to type:
nvm install <node_version**>
** the actual version you can find in Node website
Then you will have Node and you will be able to use npm commands
In my case, reinstalling node solved the issue. Anyone can install node via below website:
https://nodejs.org/en/download/
It works for me in zsh. Try nvm install --latest-npm
In my case nvm seemed to have forgotten the global default - maybe some install i did since first adding it.
Simply re-aliasing did the trick:
nvm alias default [insert version number here]
Open a new terminal in order for this to take effect
In my case, i installed node with NVM and after installing z Shell, node and nvm command didn't worked. So what worked for me was installing nvm again with this command :
wget https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
sudo zsh install.sh
Above commands installed nvm again, since node was already installed, it added the node path automatically in .zshrc file and everything worked.
Using Node v12+ on Mac Catalina, global dependencies are showing up in /$HOME/.npm-global/bin
Adding
export PATH="$HOME/.npm-global/bin:$PATH"
To ~/.bash_profile to keep everything in one place, and then adding
source $HOME/.bash_profile
To ~/.zshrc if it's not already there will do the trick. No need to logout and back in, just restart terminal.
Sometimes simple things work. Uninstalling node and installing again worked for me.
brew uninstall node
brew install node
npm update
FOR MAC: I tried some of the above but to no avail, could not get anything to work.
I did have BREW INSTALLED, so although this not be the best approach, with zsh, I did:
sudo chown -R $(whoami) /usr/local/share/man/man8 (for brew access)
brew update && brew install npm (I had had node installed)
npm -v (to confirm install)
nano ~/.zshrc (to empty file changes and save)
This worked for me. Hope this helps someone. #1 bothers me, but I will live with for now.
Just writing this in my terminal fixed the issue. Note that I had to write it separately in my project folder.
export PATH="$HOME/.npm-packages/bin:$PATH"
export PATH="$HOME/.node/bin:$PATH"
Source: https://cloudlinuxtech.com/npm-command-not-found-fix/
I got this message after installing using Homebrew
So I added these lines to the .zshrc and it worked.
export PATH="/usr/local/opt/node#16/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/node#16/lib"
export CPPFLAGS="-I/usr/local/opt/node#16/include"
I think the problem is more about the ZSH completion.
You need to add this line in your .zshrc:
zstyle ':completion:*' rehash true
If you have Oh-my-zsh, a PR has been made, you can integrate it until it is pulled: https://github.com/robbyrussell/oh-my-zsh/issues/3440
I had the same problem while installing Vercel CLI.
In my case, install with sudo.
example: sudo npm i -g vercel
For OSX Catalina users
brew install node#14
I'm using node 14 cause angular won't support latest version (Don't know why)..
Then
echo 'export PATH="/usr/local/opt/node#14/bin:$PATH"' >> ~/.zshrc
Add this at the end of your .zshrc file:
source $HOME/.zshrc.pre-oh-my-zsh
This instantly solved my problem.
In my case this happened after I configured my iterm2 to show git branch names. I basically made my iterm2 to look more elegant. But I noticed my vscode terminal was detecting nvm and npm commands
I have added some lines to .zshrc file when I am configuring iterm2. I had added oh-my-zsh.
But adding the below line to the top of .zshrc file worked for me. If it does not work kill vscode terminal and open it again
Hope this will help someone
export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
For Windows using windows-nvm I had issues after installing an additional version of node. My npm stopped working but only in ZSH. bash, Powershell, and cmd all worked fine. What ended up fixing it was adding an additional alias to zsh of alias npm="npm.cmd" and it started working again. I think it's zsh struggling to find the correct binary, so the .cmd file fixed this issue.
I had node installed with nvm, and the issue i had is that i had 2 versions of node, and i used them with command nvm use v12.xx.0. But somehow they both got detached, and i had to use it again with nvm one of them, and it started to work again how it should.
So the command is(if you have at least one version installed with nvm):
nvm use vxx.xx.0
I had zsh shell and Node installed along with npmrc. I had been using it for years when suddenly it started giving me this error. None of the answers here helped me with this problem.
Turns out I had recently updated my Node version and I had to install npmrc again. So if anyone is having this problem after upgrading their node version, try
npm install -g npmrc

Resources