Related
I am trying to install Homebrew onto my M1 Mac. My default shell is zsh and I want to keep it that way. I ran:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
and it said the installation was successful however after trying the command brew doctor and brew help both returned the error zsh: command not found: brew
I don't know a whole lot about shells or programming so anything I can try would be helpful.
I then was about to try un/re installing it and ran:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
but a warning came up to migrate to this command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"
this leads me to believe maybe it is just located in the wrong shell?
cd /opt/homebrew/bin/
PATH=$PATH:/opt/homebrew/bin
cd
touch .zshrc
echo export PATH=$PATH:/opt/homebrew/bin >> .zshrc
Run the commands in that order in terminal, you'll be editing the path and creating the missing .zshrc file, exporting the path to this new file.
Now you should be able to use:
brew doctor
It should say: "Your system is ready to brew."
The bash deprecation warning from macOS can safely be ignored, or you can add export BASH_SILENCE_DEPRECATION_WARNING=1 to ~/.bashrc` to permanently silence it.
The initial brew setup script you're using was deprecated, you'll want to use /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)". I've skimmed that script and I think it's actually zsh compatible too, but not 100% sure. This will set it up to be accessible by any shells, as long as you have /usr/local/bin in your PATH. (export PATH="/usr/local/bin:$PATH" in your ~/.zshrc, or path+=/usr/local/bin to use the zsh-specific syntax).
If you run which zsh you should still see some output; if your default shell did get changed some, you can change it back using chsh -s /bin/zsh.
EDIT:
I missed that you said you have an M1 Mac. According to the install script, the brew prefix is /opt/homebrew on ARM-based Macs (apparently this is to work around needing sudo for operations in /usr/local). I don't have a new Mac to test with, but adding path+=/opt/homebrew/bin to a new file at ~/.zshrc should to the trick.
This has helped me:
Add Homebrew to your PATH in ~/.zprofile:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
I encountered the same issue and solved it with these steps:
From the terminal, command sudo vi ~/.zshrc
Enter insert mode (type I on your keyboard) then paste
export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
Type :wq! to write and quit vim.
Close the terminal.
Reopen the terminal and type brew to confirm it's working.
If the issue persists:
By default, Homebrew installs some packages in these directories:
/usr/local/bin/brew , /usr/local/share/doc/homebrew.
It's worth checking if HomeBrew is inside these. To open finder on a Mac, command + shift + G. If you're unable to locate it, you may need to reinstall it.
I'm using a Macbook, macOS Big Sur - version 11.6.4
i get the seam problem.
so i install it again. i copy this command to the terminal.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
when i get the tips
Next steps:
- Run these three commands in your terminal to add Homebrew to your PATH:
echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/ven/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/ven/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
https://docs.brew.sh
than i copy three commands into the termainal one by one
echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/ven/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/ven/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
typeing 'brew' in the terminal, than it's working.
In my case (macOS M1) homebrew worked very inconsistently - the not found error appeared every time I ran a brew command in a fresh terminal session. Turns out that the opt/homebrew/... values in .zshrc were getting overwritten by other PATH values at some point. Ordering is crucial here.
So to add to #6754534367 's answer, you want to make sure your PATH reflects homebrew having priority over other PATH values (placed before most other values). See also: https://stackoverflow.com/a/35677348/11705094.
PS: handy to include the sbin PATH too.
In the end my .zshrc file looked as follows (e.g.):
export PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/joris.van.der.burgh/Library/Application_Support/JetBrains/Toolbox/scriptseval
After doing so, my homebrew worked consistently and no more doctors were needed.
I am on a M2 MacBook and you jest need to follow instructions brew gives after installation!
I'm a new python user. When I was installing postgresql and running the following order:
$vi ~/.bash_profile
Add PATH=/usr/pgsql-9.2/bin:$PATH before export PATH.
$source ~/.bash_profile
My terminal became very strange. It seemed that I could not logout of the .bash_profile environment. When I use any basic comments like cd, open, etc., something strange happens.
This is my output:
MynametekiMacBook-Air:~ Myname$ cd Documents/
-bash: dirname: command not found
MynametekiMacBook-Air:Documents Myname$ open ~/.bash_profile
-bash: open: command not found
MynametekiMacBook-Air:Documents Myname$ easy_install pip
-bash: easy_install: command not found
How would I fix this?
If you enter
$nano ~/.bash_profile
you will be able to edit your bash profile, you can remove the line that you added that is causing problems and try again, or see if there is a syntax error in what was entered. Once you've finished your edits you need to press ctl+o then enter to confirm and ctl+x to exit back to the bash prompt.
run /bin/mv ~/.bash_profile ~/.bp. Close your terminal. Reopen and look at the new .bp file with vim ~/.bp. Fix any errors and run mv ~/.bp ~/.bash_profile to revert.
Try export PATH=$PATH:/usr/pgsql-9.2/bin instead of Add PATH=/usr/pgsql-9.2/bin:$PATH. Because it looks like you made so your paths are being overwritten instead of being updated.
When using OSX’s git, after I modify a file I can simply do git commit <tab>, and that’ll auto complete the file’s name to the one that was modified. However, if I install a newer version of git from homebrew and I use it, that feature no longer works (meaning I press <tab> and it just “asks” me what file I want to do it on, even including the ones that have no changes).
Can anyone shed some light as to why, and how to solve that? I’d prefer using homebrew’s git, since it’s more up-to-date.
My shell is zsh, and Neither installing bash-completion or zsh-completions worked (even after following homebrew’s post-install instructions).
Also, after installing git with homebrew it says
Bash completion has been installed to: /usr/local/etc/bash_completion.d
zsh completion has been installed to: /usr/local/share/zsh/site-functions
So shouldn’t I be able to use one of those?
You're looking for:
brew install git bash-completion
As warpc's comment states, you'll need to add the following to your ~/.bash_profile to get homebrew's bash-completion working:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
The above is mentioned in the caveats when you install the bash-completion formula.
Note: if you are using Bash v4 or later (via brew install bash) then you're going to want to use brew install bash-completion#2, to enable tab completion add the following to ~/.bash_profile as described in the caveats:
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
The additional export is necessary for git, docker, youtube-dl, and other completions which may be included in the $(brew --prefix)/etc/bash_completion.d/ directory.
This get's git tab completion working on OSX without having to restart your terminal:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
echo "source ~/.git-completion.bash" >> ~/.bash_profile
source ~/.bash_profile
EDIT: this doesn't work in Catalina's default zsh shell. I changed the default shell back to bash and it works again. https://www.howtogeek.com/444596/how-to-change-the-default-shell-to-bash-in-macos-catalina/
In case anyone else makes my dumb mistake, try brew install git. I was using the git that comes with Xcode and didn't realize that I had never installed Homebrew's git to get the autocompletions.
for some reason I was missing the file at $(brew --prefix)/etc/bash_completion so #Graham Perks' correct answer didn't work for me
It ended up the fix in my case was:
brew unlink bash-completion
brew link bash-completion
I solved the problem by figuring out that $(brew --prefix)/etc/bash_completion returned Permission denied when executed. So after a simple:
chmod +x $(brew --prefix)/etc/bash_completion
Everything is now working fine. I'm wondering why Homebrew doesn't make the bash_completion file executable on installation, though.
For bash on macOS Catalina (3/30 update: Big Sur too), if you want to also use Bash 5 from homebrew, you need to make sure that your login shell is set to homebrew's bash, and not the default.
To check if you need to do this, run echo ${BASH_VERSION}. If you see a version starting with 3, you are not using Brew's bash for your login shell.
To change this,
Open System Preferences->Users and Groups.
Right click your user and select "Advanced Options". You may need to unlock this with your password by clicking the lock in the bottom left.
Set the login shell field to the location of your brew's bash, which you can usually find by running which bash in a terminal after you install brew's bash. Mine was /usr/local/bin/bash.
Restart your terminal, and follow the instructions in this excellent answer
Found a working solution. It's very recent (authored 16 hours ago, and committed 2 hours ago), and it comes directly from homebrew.
brew install git --without-completions
Just tried it, and it finally works as intended.
I had the same issue and even found this post this morning. I fixed the issue by updating brew with brew update and then reinstalling git with brew reinstall git.
I was then notified of another file that is blocking the homebrew linking process, in my case it was /usr/local/share/zsh/site-functions/git-completion.bash. Removing the file and running brew link git solved the issue. Guessing it was just a bad recipe version we stumbled upon.
If you have $BASH_VERSION < 4.1, eg 3.2.57(1)-release then go ahead with:
brew install bash-completion
# In ~/.bash_profile :
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
However if you've brew install bash to get version 4.4.12(1)-release
you can use the better and more complete completions in:
brew install bash-completion#2
# In ~/.bash_profile:
[ -f "$(brew --prefix)/share/bash-completion/bash_completion" ] \
&& . "$(brew --prefix)/share/bash-completion/bash_completion"
Note that some packages (brew, docker, tmux) will still put some completions into $(brew --prefix)/etc/bash_completion.d/ so you might add:
for completion in "$(brew --prefix)/etc/bash_completion.d/"*
do
. $completion
done
Finally you should be able to add the git completion script if for some reason the way you installed git did not add it to either of those:
[[ -f $(brew --prefix)/etc/bash_completion.d/git \
|| -f $(brew --prefix)/share/bash-completion/completions/git ]] \
|| curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash \
-o $(brew --prefix)/etc/bash_completion.d/git
You can get and add it with the above.
Step 1: Download auto completion script:
cd ~
curl -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
Step 2: Update .bash_profile and .bashrc
echo "source ~/git-completion.bash" >> .bash_profile
Via https://www.anintegratedworld.com/git-tab-autocomplete-on-osx-10-11-el-capitan/
If above does not work, try https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion
In 2019, using Bash v5, you do not need to explicitly source the git bash completion script in your .bash_profile or .bashrc
Ensure you have the following two lines in your .bashrc
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
Download the git bash completion script (https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash) and save it to /usr/local/etc/bash_completion.d/ as git
That's it! Bash will automatically pick up the git completion file and enable completion.
Side Note: I recommend putting all these changes in .bashrc as this ensures that when you drop into an interactive shell (ie. from pipenv shell), completions will get loaded correctly as bash will source .bashrc and NOT .bash_profile.
For me , I had to put
source $(brew --prefix)/etc/bash_completion
into .bashrc (not .bash_profile) to get this to work.
".bash_profile is executed for login shells, while .bashrc is executed
for interactive non-login shells" -- from What is the difference between .bash_profile and .bashrc? It appears to me that MacOS Sierra doesn't execute .bash_profile when opening a new terminal window, only .bashrc.
I wouldn't put it in _bash_profile, because then I'd have to reboot/logout for updates to take effect.
This worked for me in Mojave (OSX 10.14.1):
brew install bash-completion
Then add the following line to your ~/.bash_profile:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
It may have something to do with libedit being used instead of readline in Lion.
Try installing readline before git.
brew install readline
For those who already have brew bash-completion installed. I did not have the git completion script installed and could not find any tap for that.
So I added it manually:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o $(brew --prefix)/etc/bash_completion.d/git
Note that you have to rename the file and remove the extension for it to work.
If you do not have completion or git installed, install it in the accepted answer.
brew install git bash-completion
If you used homebrew to install git, then probably there is no need to install anything to support git completion.
"git-completion.bash" file is somewhere (mine was here: /usr/local/git/contrib/completion/git-completion.bash)
All you need to do is to find the file:
sudo find / -type f -name "git-completion.bash"
Then source its path in your .bash_profile.
For example I needed to add this line to my ~/.bash_profile:
source /usr/local/git/contrib/completion/git-completion.bash
Don't forget to source your ~/.bash_profile or reopen your terminal ;)
from:
how-enable-git-tab-completion-bash-mac-os-x
I know this is an old post, but you don't really need to install any additional packages.
Homebrew is informing you that there is a directory with all the stuff you need.
You can simply add the following line to your .bash_profile if you are using Bash:
source /usr/local/etc/bash_completion.d/git-completion.bash
If nothing works, it could be because you have an older version of bash and bash completion script is not getting sourced by the /usr/local/etc/profile.d/bash_completion.sh script. You can test this by adding a simple echo inside the conditionals in file /usr/local/etc/profile.d/bash_completion.sh:
10 if shopt -q progcomp && [ -r /usr/local/Cellar/bash-completion#2/2.11/share/bash-completion/bash_completion ]; then
11 # Source completion code.
echo "doing bash completion or not"
12 . /usr/local/Cellar/bash-completion#2/2.11/share/bash-completion/bash_completion
And open a new terminal. If you don't see the echo message, then the conditionals do not evaluate to true. In my case it was because the bash version was old, the default from mac 3.2.blah.
I did install a newer bash from brew, but i forgot to chsh and that caused me a lot of headache. bash --version would return 5.1.8 but the enabled shell was still the old one :) To test the enabled bash you can do
for n in {0..5}
do
echo "BASH_VERSINFO[$n] = ${BASH_VERSINFO[$n]}"
done
The fix was to sudo chsh -s /usr/local/bin/bash After which the completions worked.
After tearing my hair out over this one for ages, I discovered that when I had the hub command installed, the completions for the hub command were breaking the completions for git. I had to remove /usr/local/etc/bash_completion.d/hub.bash_completion.sh. This meant no completions for hub, but git completions now worked. I didn't debug why this was.
I had the following brew packages installed:
bash: 5.1.16
bash-completion#2: 2.11
git: 2.35.1
hub: 2.14.2
Enable Auto Completion of GIT commands on MAC-OS Mojave 10.14
I am a developer and use GIT from the command line all of the time. When I consider the development perspective, I used to execute a lot of commands using the command line for GIT operations. Most of the time it is very annoying that MAC OS doesn't have automatic support for the command completion which I partially support. as well as the command suggestions, which means what are the commands available for typed characters. So it is very troublesome to type very long command and mostly repetitive task as typo going wrong. :(
Tab completion would certainly be faster and easier. Unfortunately, the default installation of git on some Mac computers doesn't have tab completion enabled.
So that I was searching for a fix for the problem and there are several solutions found from the web search such as StackOverflow, GitHub as well as from the medium. Unfortunately, those solutions did not work for me and got frustrated with trying different solutions so many times.
I was searching deeply and trying out different solutions and fortunately, it is an easy fix. Below are the steps I have collected from several posts and finally it worked as expected. So I hope to share with others who have this problem like me.
f you go to the web search and you can find many solutions which mentioned the git completion bash file. Even GitHub guide as well. But I suggest you check first if the git-completion.bash file is already in your MAC computer with the git-core or something else which came from installation. you can use below command.
sudo find / -type f -name "git-completion.bash"
you will get below results. (may have some difference according to the content)
/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash
/Users/Dilanka/git-completion.bash
/Users/Dilanka/.oh-my-zsh/plugins/gitfast/git-completion.bash
/Users/Dilanka/Downloads/git-completion.bash
I suggest you to pick which installed from git-core
If the git-completion.bash script doesn't exist on your machine, please retrieve it from the below provided above and save it to your local machine in a new file called git-completion.bash in the /usr/local/etc/bash_completion.d/ directory.
https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks
If you use the Bash shell, Git comes with a nice auto-completion script you can enable. Download it directly from the Git source code at
https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
If the git-completion.bash script exists on your machine, but is not in the /usr/local/etc/bash_completion.d/ directory, you should create that directory and copy the file into it. Below command will do the job:
sudo mkdir /opt/local/etc/bash_completion.d
sudo cp /Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash /usr/local/etc/bash_completion.d/git-completion.bash
After the completion of above. The git-completion.bash script should exist on your local machine in the/usr/local/etc/bash_completion.d/ directory.
Now you need to refresh your profile using below command. It will load your added bash file to the terminal context.
source ~/.bash_profile
Great!!! you have done it. Just start the terminal window and try it. Just type "git sta" it will show suggestions as below:
git sta
stage stash status
git chec<TAB> will show git checkout
see my GitHub post here:
https://github.com/DIL8654/Enable-Auto-Completion-of-GIT-commads-on-MAC-OS-Mojave
See my Medium post here:
https://medium.com/#dilanka85/enable-auto-completion-of-git-commands-on-mac-os-mojave-10-14
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
I know this might be more appropriate at Ask Different, but as I tried adding tags there, there was no vim tag, only macvim. So I figured I might get a better audience here.
In the Terminal, I do the following
$ vim --version
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jan 31 2010 13:33:49)
When I browse to http://www.vim.org, I see a news item
Vim 7.3 released!
How do I update my built-in vim? I would very much like to do it cleanly (i.e. no duplicate installations, or any additional downloads, no macports, etc.)
I considered using Mercurial (as I already use it for other things), as per the instructions here.
$ hg clone https://vim.googlecode.com.hg/ vim
$ cd vim/src
$ make
But I think that would make a duplicate installation. Despite my "clean" requirement as mentioned above, "unclean" solutions are also welcome, since maybe there really is no other way.
If I understand things correctly, you want to install over your existing Vim, for better or worse :-) This is a bad idea and it is not the "clean" way to do it. Why? Well, OS X expects that nothing will ever change in /usr/bin unbeknownst to it, so any time you overwrite stuff in there you risk breaking some intricate interdependency. And, Let's say you do break something -- there's no way to "undo" that damage. You will be sad and alone. You may have to reinstall OS X.
Part 1: A better idea
The "clean" way is to install in a separate place, and make the new binary higher priority in the $PATH. Here is how I recommend doing that:
$ # Create the directories you need
$ sudo mkdir -p /opt/local/bin
$ # Download, compile, and install the latest Vim
$ cd ~
$ hg clone https://bitbucket.org/vim-mirror/vim or git clone https://github.com/vim/vim.git
$
$ cd vim
$ ./configure --prefix=/opt/local
$ make
$ sudo make install
$ # Add the binary to your path, ahead of /usr/bin
$ echo 'PATH=/opt/local/bin:$PATH' >> ~/.bash_profile
$ # Reload bash_profile so the changes take effect in this window
$ source ~/.bash_profile
Voila! Now when we use vim we will be using the new one. But, to get back to our old configuration in the event of huge f*ckups, we can just delete the /opt directory.
$ which vim
/opt/local/bin/vim
$ vim --version | head -n 2
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Aug 27 2011 20:55:46)
MacOS X (unix) version
See how clean this is.
I recommend not to install in /usr/local/bin when you want to override binaries in /usr/bin, because by default OS X puts /usr/bin higher priority in $PATH than /usr/local/bin, and screwing with that opens its own can of worms.... So, that's what you SHOULD do.
Part 2: The "correct" answer (but a bad idea)
Assuming you're set on doing that, you are definitely on track. To install on top of your current installation, you need to set the "prefix" directory. That's done like this:
hg clone https://bitbucket.org/vim-mirror/vim or git clone https://github.com/vim/vim.git
cd vim
./configure --prefix=/usr
make
sudo make install
You can pass "configure" a few other options too, if you want. Do "./configure --help" to see them. I hope you've got a backup before you do it, though, in case something goes wrong....
Don't overwrite the built-in Vim.
Instead, install it from source in a different location or via Homebrew or MacPorts in their default location then add this line to your .bashrc or .profile:
alias vim='/path/to/your/own/vim'
and/or change your $PATH so that it looks into its location before the default location.
The best thing to do, in my opinion, is to simply download the latest MacVim which comes with a very complete vim executable and use it in Terminal.app like so.
alias vim='/Applications/MacVim.app/Contents/MacOS/Vim' # or something like that, YMMV
Like Eric, I used homebrew, but I used the default recipe. So:
brew install mercurial
brew install vim
And after restarting the terminal homebrew's vim should be the default. If not, you should update your $PATH so that /opt/homebrew/bin is before /usr/bin. E.g. add the following to your .profile:
export PATH=/opt/homebrew/bin:$PATH
Note: Previous versions of Homebrew did install to /usr/local, so in that case you have to use /usr/local/bin instead of /opt/homebrew/bin.
A note to romainl's answer: aliases don't work together with sudo because only the first word is checked on aliases. To change this add another alias to your .profile / .bashrc:
alias sudo='sudo '
With this change sudo vim will behave as expected!
On Yosemite, install vim using brew and the override-system-vi option. This will automatically install vim with the features of the 'huge' vim install.
brew install vim --with-override-system-vi
The output of this command will show you where brew installed vim. In that folder, go down into /bin/vim to actually run vim. This is your command to run vim from any folder:
/usr/local/Cellar/vim/7.4.873/bin/vim
Then alias this command by adding the following line in your .bashrc:
alias vim="/usr/local/Cellar/vim/7.4.873/bin/vim"
EDIT: Brew flag --override-system-vi has been deprecated. Changed for --with-override-system-vi. Source: https://github.com/Shougo/neocomplete.vim/issues/401
brew install vim --override-system-vi
This blog post was helpful for me. I used the "Homebrew built Vim" solution, which in my case saved the new version in /usr/local/bin. At this point, the post suggested hiding the system vim, which didn't work for me, so I used an alias instead.
$ brew install vim
$ alias vim='/path/to/new/vim
$ which vim
vim: aliased to /path/to/new/vim
I just installed vim by:
brew install vim
now the new vim is accessed by vim and the old vim (built-in vim) by vi