I've installed mysql 5.7 via brew. The binary files are installed at /usr/local/opt/mysql\#5.7/bin/ however I can't access these files as this location isn't in my path.
Is there a brew way to fix this rather than me making symlinks around the system myself?
The Homebrew way of "fixing" this is to use link --force:
brew link --force mysql#5.7
Alternatively, you can add this location to your $PATH by modifying it in your ~/.bashrc or ~/.bash_profile:
export PATH="$(brew --prefix mysql#5.7):$PATH"
The simple "brew way" to do this is answered here
$ brew info mysql (to get info about the installed versions)
$ brew switch mysql 5.7.21 (to switch to a stable version)
I removed ALL content from /usr/local/bin folder (including 'brew'). Homebrew isn't working anymore and I seem to be stuck in a limbo. When I try to install it says:
It appears Homebrew is already installed. If your intent is to
reinstall you should do the following before running this installer
again:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
When I run the given uninstall command it says:
Failed to locate Homebrew!
Background
The problem arose when I attempted to remove node.js by following this guide:
https://stackoverflow.com/a/11178106/1736012
To completely uninstall node + npm is to do the following:
go to /usr/local/lib and delete any node and node_modules
go to /usr/local/include and delete any node and node_modules directory
if you installed with brew install node, then run brew uninstall node in your terminal
check your Home directory for any local or lib or
include folders, and delete any node or node_modules from there
go to /usr/local/bin and delete any node executable
Especially 5 was bad! That's what led me to remove everything under /usr/local/bin. So brew doctor won't work (brew isn't recognized anymore). Brew worked fine before this.
What I tried
This does not work either as brew is missing:
rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install )"
I tried various scripts like this one for example: https://apple.stackexchange.com/a/85481. And this: https://gist.github.com/SteveBenner/11254428. None of them is working (both assumes that brew command is there)...
What can I do to re install Homebrew so that it works as before??
This should bring back a working brew command:
cd /usr/local/Homebrew
git init
git remote add origin https://github.com/Homebrew/homebrew
git pull origin master
Next I would check the output of brew doctor and see if there are major problems. There is an official uninstalling guide on homebrew's github wiki in case you want to completely uninstall.
Try to move or remove the Homebrew file in the user/local file and then try the regular link from the homebrew homepage to install the brew!
By the way, I did not try moving but I am pretty sure it should work.
Note: While the operation you might have to use the sudo
I faced the same issue, the following link really worked for me
https://github.com/Homebrew/brew/issues/10368
especially comment from MrBenFTW commented on Feb 2021
I'm using homebrew and oh-my-zsh on a fresh OSX 10.10.1 install. I got nvm via homebrew and then attempted to run it but says - zsh: command not found: nvm
Any idea what the problem is? I was able to install and use git just fine...
UPDATED 9/20/2019
As stated by more recent answers from DarkPurple141 and Elise van Looij. nvm doesn't appear to be compatible with homebrew. This is also stated in the official nvm-sh repo located here.
Homebrew installation is not supported. If you have issues with
homebrew-installed nvm, please brew uninstall it, and install it using
the instructions below, before filing an issue.
Note: If you're using zsh you can easily install nvm as a zsh plugin.
Install zsh-nvm and run nvm upgrade to upgrade.
The following steps should help:
$ brew uninstall nvm
$ brew cleanup (just for good measure)
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
Check that nvm was installed correctly by running $ command -v nvm.
4.a If the response is anything other than $ nvm, add the following two lines to the ~/.bash-profile file:
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
4.b Restart your computer (you can try closing Terminal and restarting it first)
4.c $ command -v nvm should now return nvm`
Now update Node.js with $ nvm install --lts
Update npm: $ nvm install-latest-npm
$ npm install --global mocha. Finally, success! Well, for me and I hope for you too.
Did you follow the instructions listed in the caveats?
[~] brew info nvm
nvm: stable 0.20.0, HEAD
https://github.com/creationix/nvm
Not installed
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/nvm.rb
==> Caveats
Add the following to $HOME/.bashrc, $HOME/.zshrc, or your shell's
equivalent configuration file:
source $(brew --prefix nvm)/nvm.sh
Node installs will be lost upon upgrading nvm. Add the following above
the source line to move install location and prevent this:
export NVM_DIR=~/.nvm
Without the extra config it doesn't look like it will find NVM by default..
There are TWO things you need to do. Follow the caveats shown after installing nvm via brew, and THEN you need to activate/reload the .bash_profile changes.
Run brew install nvm
Follow caveats shown in console, mine were as follows, yours MAY be different!:
Add the following to ~/.bash_profile or your desired shell
configuration file:
export NVM_DIR="$HOME/.nvm"
. "$(brew --prefix nvm)/nvm.sh"
Run . ~/.bash_profile to apply the changes you made to your .bash_profile file
I've spent a couple of hours going round and round on this issue, but I've come to the conclusion that DarkPurple141 is right: nvm just isn't compatible with Homebrew, as they state on their Github nvm-sh/nvm Node Version Manager. Homebrew will install nvm and everything looks fine, until one tries to get npm to install a module, Mocha in my case. That threw me right back to the dreaded error:
ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
NOTE: On step 3, make sure to replace version with correct release.
The solution, on MacOS 10.14 Mojave, was:
$ brew uninstall nvm
$ brew cleanup (just for good measure)
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
Check that nvm was installed correctly by running $ command -v nvm.
4.a If the response is anything other than $ nvm, add the following two lines to the ~/.bash-profile file:
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
4.b Restart your computer (you can try closing Terminal and restarting it first)
4.c $ command -v nvm should now returnnvm`
Now update Node.js with $ nvm install --lts
Update npm: $ nvm install-latest-npm
$ npm install --global mocha. Finally, success! Well, for me and I hope for you too.
While the accepted answer does technically work, it's worth noting that Homebrew installation is not officially supported by the nvm package. The recommended way to avoid issues like those raised above is to apply either of the below methods of installation.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
# or wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
source: https://github.com/creationix/nvm
To install nvm, brew install nvm
To run nvm after installation or just once, $(brew --prefix nvm)/nvm.sh
To run nvm everytime zsh opens
nano ~/.zshrc
Add this line source $(brew --prefix nvm)/nvm.sh
The reason you would need to reload your bash profiles or any other bash files might be because the command nvm may not be a program but a function that is defined and can only be used if the corresponding bash file is sourced.
On a system that I checked
which nvm
does not work but
nvm list
does. This means that you can use the word "nvm" to invoke something. That something isn't a program. In the current case, it is a function which can be verified by
typeset -F | grep -P ' nvm$'
which outputs
declare -F nvm
which means nvm is a function, whose body can be inspected by doing
type -F nvm
One possibility if brew was used is that the nvm may be unlinked, especially if it was installed by another MAC OS user.
In this case, execute:
brew link nvm
I'd like to add that nvm's location on github changed and the version bumped.
The curl command now should be:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
if you happen to be using fish shell, consider https://github.com/jorgebucaran/nvm.fish
Instructions from
lukechilds/zsh-nvm#as-an-oh-my-zsh-custom-plugin
If you are using mac os + zsh + oh-my-zsh:
Clone zsh-nvm into your custom plugins repo
git clone https://github.com/lukechilds/zsh-nvm ~/.oh-my-zsh/custom/plugins/zsh-nvm
Then load nvm as a plugin in your .zshrc file
plugins+=(zsh-nvm)
Keep in mind that plugins need to be added before oh-my-zsh.sh is sourced.
f.e.
$ nano ~/.zshrc
// edit .zshrc contents
...
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
# docs: f.e. https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/kubectl
plugins=(zsh-nvm)
source $ZSH/oh-my-zsh.sh
...
Finally reload the configuration $ source ~/.zshrc
I tried to update my git version on Mac OS X 10.7, but it doesn't change the version.
It's still on 2.0.
If I run,
rm -rf /usr/local/git
rm /etc/paths.d/git
rm /etc/manpaths.d/git
the new version gets uninstalled, but the old one is still there (git is still a valid command).
How can I find the directory where this "ghost" version is installed?
To see where git is installed:
which git
See for instance those guides:
"Beginner's Setup Guide for Git & Github on Mac OS X"
"Install and Update to latest version Git on Mac OSX 10.10 Yosemite"
The location usually is:
/usr/local/git/bin/git
As mentioned in "Can't seem to uninstall git":
/opt/local/bin is the location of software installed by macports, so you'll want to run this:
sudo port uninstall git
If you see /usr/local/bin/git, that is likely a brew installation: see "Can't use homebrew installed git":
brew uninstall git
# make sure everything is alright, maybe brew will give you some hint
brew doctor
brew update
brew install git
# magic happen, brew will give you hint /usr/bin occurs before /usr/local/bin
# and recommend you run following command
brew doctor
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
Currently I am using Node.js v0.6.16 on Mac OS X 10.7.4. Now I want to upgrade it to the latest Node.js v0.8.1. But after downloading and installing the latest package file from nodejs.org, I found that system is still using v0.6.16 instead of v0.8.1 when I typed "node -v" in a terminal. Is there any step that I have missed? Or, should I thoroughly uninstall the old version before installing the latest one?
BTW, I know that nvm can help to manage the nodejs package
https://github.com/creationix/nvm/
Is there any way to upgrade the Node.js without using it?
I have googled this problem, but it seems to me that there is no very clear answer to this question for the latest Node.js.
Here's how I successfully upgraded from v0.8.18 to v0.10.20 without any other requirements like brew etc, (type these commands in the terminal):
sudo npm cache clean -f (force) clear you npm cache
sudo npm install -g n install n (this might take a while)
sudo n stable upgrade to the current stable version
Note that sudo might prompt your password.
Additional note regarding step 3: stable can be exchanged for latest, lts (long term support) or any specific version number such as 0.10.20.
If the version number doesn't show up when typing node -v, you might have to reboot.
These instructions are found here as well: davidwalsh.name/upgrade-nodejs
More info about the n package found here: npmjs.com/package/n
More info about Node.js' release schedule: github.com/nodejs/Release
If you initially installed Node.js with Homebrew, run:
brew update
brew upgrade node
npm install -g npm
Or as a one-liner:
brew update && brew upgrade node && npm install -g npm
A convenient way to change versions is to use n:
brew install n
To install the latest version of Node.js with n:
n latest
Or, to install the latest LTS version with n:
n lts
Alternatively, you could use nvm instead of n:
brew install nvm
To install the latest version of Node.js with nvm:
nvm install node
If you installed via a package, then download the latest version from nodejs.org.
See Installing Node.js and updating npm.
Because this seems to be at the top of Google when searching for how to upgrade nodejs on mac I will offer my tip for anyone coming along in the future despite its age.
Upgrading via NPM
You can use the method described by #Mathias above or choose the following simpler method via the terminal.
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
After which you may opt to confirm the upgrade
node -v
Your nodejs should have upgraded to the latest version. If you wish to upgrade to a specific one say v0.8.19 then instead of
sudo n stable
use
sudo n 0.8.19
EDIT
Avoid using sudo unless you need to. Refer to comment by Steve in the comments
Go to http://nodejs.org and download and run the installer.
It works now - for me at least.
You could install nvm and have multiple versions of Node.js installed.
curl https://raw.github.com/creationix/nvm/master/install.sh | sh
source ~/.nvm/nvm.sh
and then run:
nvm install 0.8.22 #(or whatever version of Node.js you want)
you can see what versions you have installed with :
nvm list
and you can change between versions with:
nvm use 0.8.22
The great thing about using NVM is that you can test different versions alongside one another. If different apps require different versions of Node.js, you can run them both.
I use Node version manager (called n) for it.
npm install -g n
then
n latest
OR
n stable
Simply go to node JS Website and install the latest version.
Do install latest version instead of the recommended stable version. It will give you freedom to use latest ES6 Features on node.
Can be Found here Node JS.
also to update npm, you will have to use this command.
sudo npm i -g npm#latest
All your projects will work fine.
Update: 2020 another good option is to use nvm for node which can then support multiple versions.
use nvm install --lts to always be able to update to latest node version use nvm ls-remote command to to check new versions of node.
Other option for mac :: brew update && brew install node && npm -g npm
Upgrade the version of node without installing any package, not even nvm itself:
sudo npx n stable
Explanations:
This approach is similar to Johan Dettmar's answer. The only difference is here the package n is not installed glabally in the local machine.
On macOS the homebrew recommended way is to run
brew install node
npm install -g npm#latest
I am able to upgrade the node using following command
nvm install node --reinstall-packages-from=node
There are five different ways (and counting?) to update Node.js on Mac:
Install the newer binary by downloading from nodejs.org
Update Node.js through Homebrew
Command: brew update && brew upgrade node
Update Node.js using Node Version Manager (NVM)
Command: nvm install {version} && nvm use {version}
Update Node.js using n package manager
Command: sudo n latest
Update Node.js through MacPorts
Command (same version update): sudo port selfupdate && sudo port upgrade {version}
If you are still using older MacOS version, it may be better to use lightweight, special-purpose package manager like n or nvm. You can refer to this sample use case for updating Node.js on old Mac (High Sierra).
Now this works for me:
sudo npm install -g n
sudo n latest
Happy code!
sadly, n doesn't worked for me. I use node version manager or nvm and it works like a charm. heres the link on how to install nvm: https://github.com/creationix/nvm#installation
nvm i 8.11.2 upgrade to latest LTS
nvm use 8.11.2 use it
node -v check your latest version
Go to the website nodejs.org and download the latest pkg then install.
it works for me
I used brew to upgrade my node. It has installed but it located in /usr/local/Cellar/node/5.5.0 and there is a default node in /usr/local/bin/node which bothers me. I don't want to make soft link because I don't really know how brew is organized.
So I download the pkg file, installed and I got this info:
Node.js was installed at
/usr/local/bin/node
npm was installed at
/usr/local/bin/npm
Make sure that /usr/local/bin is in your $PATH.
Now the upgrade is completed
Pretty Simple.
sudo npm i -g n
Then you can specify the version you want.
sudo n 12.8.0
Cheers!!
You can run but you can't hide... At the end you will be using NVM anyways.
You can just go to nodejs.org and download the newest package. It will update appropriately for you. NPM will be updated as well.
I think the simplest way to use the newest version of Node.js is to get the newest Node.js pkg file in the website https://nodejs.org/en/download/current/
if you want to use different version of Node.js you can use nvm or n to manage it.
sudo npm install -g n
and then
sudo n latest for linux/mac users
For Windows please reinstall node.
These 2 methods I tried are not working:
Use npm
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Manual install node from official website (https://nodejs.org/en/)
After trying, node -v still shows the old version of node.
Below method works for me:
Step 1: Install nvm (for more details: https://github.com/creationix/nvm#installation)
Open terminal and type this command:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
Close terminal and reopen it.
Type this command to check if nvm is installed:
command -v nvm
Step 2: To download, compile, and install the latest release of node, type this:
nvm install node ("node" is an alias for the latest version)
To check if node gets the latest version (v10.11.0).
Installing the latest node also installs the latest npm.
Check if npm gets the latest version (6.4.1).
Easy nad Safe Steps
Step 1: Install NVM
brew install nvm
Step 2: Create a directory for NVM
mkdir ~/.nvm/
Step 3: Configure your environmental variables
nano ~/.bash_profile
PASTE BELOW CODE
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
source ~/.bash_profile
Step 4: Double check your work
nvm ls
Step 5: Install Node
nvm install 9.x.x
Step6: Upgrade
nvm ls-remote
v10.16.2 (LTS: Dubnium)
v10.16.3 (Latest LTS: Dubnium) ..........
nvm install v10.16.3
Troubleshooting
Error Example #1
rm -rf /usr/local/lib/node_modules
brew uninstall node
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
https://www.chrisjmendez.com/2018/02/07/install/
Nvm
Nvm is a script-based node version manager. You can install it easily with a curl and bash one-liner as described in the documentation. It's also available on Homebrew.
Assuming you have successfully installed nvm. The following will install the latest version of node.
nvm install node --reinstall-packages-from=node
The last option installs all global npm packages over to your new version. This way packages like mocha and node-inspector keep working.
N
N is an npm-based node version manager. You can install it by installing first some version of node and then running npm install -g n.
Assuming you have successfully installed n. The following will install the latest version of node.
sudo n latest
Homebrew
Homebrew is one of the two popular package managers for Mac. Assuming you have previously installed node with brew install node. You can get up-to-date with formulae and upgrade to the latest Node.js version with the following.
1 brew update
2 brew upgrade node
MacPorts
MacPorts is the another package manager for Mac. The following will update the local ports tree to get access to updated versions. Then it will install the latest version of Node.js. This works even if you have previous version of the package installed.
1 sudo port selfupdate
2 sudo port install nodejs-devel
for latest release:
nvm install node
specific version:
nvm install 6.14.4
https://github.com/creationix/nvm
Use nvm to upgrade node as per the project requirement..
install nvm through homebrew..
brew update
brew install nvm
mkdir ~/.nvm
nano ~/.bash_profile
In your .bash_profile file (you may be using an other file, according to your shell), add the following :
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
source ~/.bash_profile
echo $NVM_DIR
You can directly use curl to upgrade node to the latest version. Run the following command:
curl "https://nodejs.org/dist/latest/node-${VERSION:-$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE 's|.*>node-(.*)\.pkg</a>.*|\1|p')}.pkg" > "$HOME/Downloads/node-latest.pkg" && sudo installer -store -pkg "$HOME/Downloads/node-latest.pkg" -target "/"
Reference: https://nodejs.org/en/download/package-manager/#macos
First install nvm with this command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
credirts to #Saviah Kao
Then install node:
nvm install node --reinstall-packages-from=node
credits to #Elad
I had the same problem. This is what worked for me because I downloaded and installed node.js globally from the node.js website.
What I did was Give NVM (Node Version Manager) a try. Please do the commands in the following order in your terminal
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
command -v nvm
nvm install node
node -v (to confirm the update)
This is just to add some info for people who didn't have Node installed with Homebrew but getting that very error when trying to install packages with npm on Mac OS X.
I found this good article explaining how to completely remove Node whichever the way you originally installed it.
After node, npm and n were completely removed from my machine, I just reinstalled Node.js using the official .pckg installer from Node website and everything just went back to normal.
Hope this helps out someone.
An easy way is go straight to the website
https://nodejs.org/en/download/
Click download the latest version and install pkg file.
After that you will get the latest node and npm version
I'm using a Mac Mini M1. I just removed my very old packages of node.js and npm and decided to install them using homebrew. I found out that now brew install node also installs npm. FYI