Trouble installing homebrew on New Mac - macos

Once I install homebrew on my terminal it works. But when I close the terminal and reopen to use brew, it cannot find the command.
On reopening the terminal it says:
/Users/abc/.zshrc:export:2: not valid in this context: Support/JetBrains/Toolbox/scriptseval:/opt/homebrew/bin:/opt/homebrew/bin
This is what my .zprofile looks like after installing homebrew using the official docs:
# Added by Toolbox App
export PATH="$PATH:/Users/anshgupta/Library/Application Support/JetBrains/Toolbox/scripts"
eval "$(/opt/homebrew/bin/brew shellenv)"
Please explain why does it not recognise that I have installed it and how can I fix this

OnTerminal,
~ % git clone https://github.com/Homebrew/brew homebrew
~ % eval "$(homebrew/bin/brew shellenv)"
~ % brew update --force --quiet
~ brew update
Already up-to-date.
Here brew installation documentation link - https://docs.brew.sh/Installation

Try putting the line eval "$(/opt/homebrew/bin/brew shellenv)" to the top of the file, save it and restart your terminal.

Related

Why I can't install brew on macOS?

I am trying to install brew on my co-worker's macOS. I have brew on my computer.
Not sure why we are having problems to install it on his computer. I am following this turial.
When I run:
% brew doctor
zsh: command not found: brew
It says brew was not installed.
I already edited his path at .zshrc. However, I did not put the comment suggested on the tutorial. Not sure if it makes any difference:
#Michaels-MacBook-Air ~ % cat .zshrc
export PATH=/usr/local/bin:$PATH
This is on:
#Michaels-MacBook-Air ~ % pwd
/Users/michaels
In addition, I already executed:
/bin/bash install.sh
Which return the following warning:
Warning: /opt/homebrew/bin is not in your PATH.
Instructions on how to configure your shell for Homebrew
can be found in the 'Next steps' section below.
And I checked xcode-select is installed:
#Michaels-MacBook-Air ~ % xcode-select --version
xcode-select version 2396.
I am suspicious his PATH might be wrong:
#Michaels-MacBook-Air ~ % echo $PATH
/usr/local/bin:/usr/local/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Keybase.app/Contents/SharedSupport/bin
Is this problematic?
If no, what else could be causing a problem?
From the Homebrew documentation:
This script installs Homebrew to its default, supported, best prefix (/usr/local for macOS Intel, /opt/homebrew for Apple Silicon and /home/linuxbrew/.linuxbrew for Linux)
If your coworker has an M1 or M2 mac, you'll need to add /opt/homebrew/bin to PATH.
To install brew, just run the following script:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Homebrew Official Documentation:
https://brew.sh/

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)

I use the latest Apple M1 chip processor. And I keep getting errors while application installation.
say.,
brew install openjdk#11
Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
Please create a new installation in /opt/homebrew using one of the
"Alternative Installs" from:
https://docs.brew.sh/Installation
You can migrate your previously installed formula list with:
brew bundle dump
Need help with exact steps to follow.
For what it's worth, before installing Homebrew you will need to install Rosetta2 emulator for the new ARM silicon (M1 chip). I just installed Rosetta2 via terminal using:
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
This will install rosetta2 with no extra button clicks.
After installing Rosetta2 above you can then use the Homebrew cmd and install Homebrew for ARM M1 chip: arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Once Homebrew for M1 ARM is installed use this Homebrew command to install packages: arch -x86_64 brew install <package>
Homebrew needs to be installed in two places on Apple silicon: in /usr/local for rosetta-emulated (Intel) code, and /opt/homebrew for ARM64. These are somewhat hard-coded and the /opt/homebrew one MUST be used for ARM code, as it stands today, and is non-negotiable. However, it's easy enough to install and you can follow the general instructions on the official docs. You open a Rosetta shell first.
% arch -x86_64 zsh
% cd /usr/local && mkdir homebrew
% curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
Later, to install tools under intel you can use the arch command per-command or open a zsh terminal as above.
arch -x86_64 /usr/local/homebrew/bin/brew install sometool
For the ARM architecture, you don't need to use arch but you do need to use the full path of the homebrew command.
/opt/homebrew/bin/brew install sometool
You could rename the brew commands to something like brew86 and brewARM to help keep them separate.
Run this in the terminal it fixes the issue
eval "$(/opt/homebrew/bin/brew shellenv)"
Just use:
arch -arm64 brew install package-name
replace 'package-name' with the package you want to install.
Did a temporary fix by enabling Open using Rosetta option in the terminal app from Utilities folder.
However, it would be great to know the actual solution for this question to use the native way.
There is a lot of helpful info in the replies here, but there doesn't seem to be a direct answer to the original request, "Need help with exact steps to follow."
In case it may help people facing this issue in the future, I'll share the exact steps that I followed to resolve the issue.
The following CLI commands are intended to be run on an Apple silicon-equipped Mac in the built-in Terminal application running the macOS-default shell, Zsh:
Run a Homebrew command to confirm that an error like the following appears:
$ brew install <formula>
Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
Please create a new installation in /opt/homebrew using one of the
"Alternative Installs" from:
https://docs.brew.sh/Installation
Or:
$ brew doctor
Warning: Your Homebrew's prefix is not /opt/homebrew.
Some of Homebrew's bottles (binary packages) can only be used with the default
prefix (/opt/homebrew).
You will encounter build failures with some formulae.
If either of these errors appears, it is likely that the steps below are applicable to your case.
Navigate to the /opt folder:
$ cd /opt
Create a folder named homebrew. By default superuser privileges are required to write inside of the /opt folder, which means that it is necessary to use sudo:
$ sudo mkdir homebrew
Grant write access to the homebrew folder so that your user can perform the Homebrew installation:
$ sudo chmod go+w homebrew
Perform the four steps listed on the "Alternative Installs" page (the page mentioned in the first error message in step 1):
Install Homebrew:
$ curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
Set Homebrew's prefix in your current Terminal session:
$ eval "$(homebrew/bin/brew shellenv)"
Update Homebrew:
$ brew update --force --quiet
Revoke write access to specific folders and files:
$ chmod -R go-w "$(brew --prefix)/share/zsh"
Set Homebrew's prefix in future Terminal sessions by adding the necessary command to one of Zsh's startup files. As far as I can tell, .zshrc is the preferred startup file for this type of command:
$ echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc
Note that if there are any other existing Terminal sessions on your machine that have been open since before running the above command, the correct Homebrew prefix will still be unset in those sessions.
Confirm that Homebrew's prefix is now properly set:
$ type -a brew
brew is /opt/homebrew/bin/brew
brew is /usr/local/bin/brew
Or:
$ brew doctor
Your system is ready to brew.
It should now be possible to continue using Homebrew normally.
This issue with new macbook pro M1 chip
Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
For Resolve follow below steps
Step1
$ brew bundle dump
Step2
$ /bin/bash -c "$(curl -fsSL
https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step3
Edit file below
$ vi ~/.bashrc or vi ~/.zshrc
Edit below line in above file
export PATH=/opt/homebrew/bin:$PATH
Homebrew is now available for the new apple M1 chip at https://docs.brew.sh/Installation. The script installs in a new location, ‘/opt/homebrew’ instead of ‘/usr/local’ which requires that you implement a couple lines of script after the install, substituting your username. You can copy/paste from the comments in your install. Just don’t skip these steps.
==> Next steps:
- Add Homebrew to your PATH in /Users/[username]/.zprofile:
echo 'eval "$(/opt/homebrew/bin/brew [username])"' >> /Users/[username]/.zprofile
eval "$(/opt/homebrew/bin/brew [username])"
Note: This works for a clean install of Homebrew on a new machine. If you have already installed an old version of Homebrew and got it working, I believe you need to uninstall that first -or- you may find this a quicker work-around http://blog.wafrat.com/homebrew-on-mac-with-m1/. Not tested.
See: https://docs.brew.sh/Installation
1. Clone homebrew
$ cd /opt
$ sudo git clone https://github.com/Homebrew/brew homebrew
2. Chown dir
$ sudo chown -R $(whoami):staff /opt/homebrew
3. Update new brew shellenv temporarily, more shellenv meaning see man brew
$ eval "$(homebrew/bin/brew shellenv)"
4. New brew update
$ brew update --force --quiet
==> Homebrew has enabled anonymous aggregate formula and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics have been recorded yet (nor will be during this `brew` run).
==> Tapping homebrew/core
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 1265097, done.
remote: Counting objects: 100% (207/207), done.
remote: Compressing objects: 100% (97/97), done.
remote: Total 1265097 (delta 120), reused 192 (delta 110), pack-reused 1264890
Receiving objects: 100% (1265097/1265097), 517.64 MiB | 3.02 MiB/s, done.
Resolving deltas: 100% (872476/872476), done.
Tapped 3 commands and 6273 formulae (6,616 files, 566.4MB).
5. Make sure remove other person write privage
$ chmod -R go-w "$(brew --prefix)/share/zsh"
6. Confirm new brew version
$ brew --version
Homebrew 3.6.0
Homebrew/homebrew-core (git revision 57f5c02ec6a; last commit 2022-09-10)
7. Brew config show
/opt/homebrew on  stable (93ea8cb2c) 💰 17:17:54
$ brew config
HOMEBREW_VERSION: 3.6.0
ORIGIN: https://github.com/Homebrew/brew
HEAD: 93ea8cb2c40e1ef25f1489b0267526bd47bc8030
Last commit: 3 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 57f5c02ec6af877482ecd8753066d6a277cd3213
Core tap last commit: 72 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_REPOSITORY: /opt/homebrew
HOMEBREW_CELLAR: /opt/homebrew/Cellar
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 10
Homebrew Ruby: 2.6.8 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: 10-core 64-bit westmere
Clang: 13.1.6 build 1316
Git: 2.32.1 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.79.1 => /usr/bin/curl
macOS: 12.5.1-x86_64
CLT: 13.4.0.0.1.1651278267
Xcode: 13.4.1
Rosetta 2: true
8. Add new brew shellenv to strart bash shell, eg. ~/.zshrc、~/.barshrc etc.
eval "$(/opt/homebrew/bin/brew shellenv)"
This also may occur if you are trying to run your command in IntelliJ Terminal. Just try to run in (Regular) Terminal.
First run this command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
then it will ask you a question, hit return, then wait for the installation to be completed. After than run this command:
brew bundle dump
Go over to https://brew.sh and use the command. It will download and install brew again correctly.
Run this command as this will resolve the issue
arch -arm64 brew install kotlin
I had installed Homebrew using iTerm enabled for the Apple ARM chip (M1), but when using a different terminal program that was Intel-based (and thus opening in Rosetta) I got this error. The latter app is seen as Intel, and thus wants to use the older Homebrew path.
Probably this error is related running brew on M1/M2 Mac instead instead of Intel based Mac, atleast that was in my case. I had previously restored a Time Machine backup from Intel to M2.
According to the Homebrew documentation, the default installation script installs Homebrew to its preferred /usr/localfor macOS Intel and /opt/homebrew for Apple Silicon.
You can well use this, as it worked well for me-
re-install brew by running this in your terminal /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
run brew bundle dump
You should be good on using brew
So I bought a new M1 and migrated to it. I took it back and migrated back. I was receiving this error. Found that I needed to run sudo rm -Rf /opt/homebrew after re-installing brew to get things flowing again. 16G Ram on the M1 didn't replace my workflow with Intel using 64G.

Error in running Homebrew on Mac OS X mavericks

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" -e:70: warning: Insecure world writable dir /usr in PATH, mode 040777 It appears Homebrew is already installed. If your intent is to reinstall you should do the following before running this installer again: rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
I have this on my terminal but I cant make use of homebrew. I need to use homebrew to install django pyhton web framework. However I don't seem to get the error here. It says its already installed but none of the brew commands work.
ghochee-macbook-pro:logs streamoid$ brew doctor -bash: brew: command not found <<<<<
Can anyone please help? I also see that there is no .bash_profile file with the PATH variable set, am I looking the right folder and file here?
It sounds like /usr/local/bin isn't on your $PATH. You can add it by running the following command in the terminal:
echo 'export PATH="/usr/local/bin:${PATH}"' >> ~/.bash_profile
Then restart your terminal for the changes to take affect.

Homebrew installs nvm but nvm can't be found afterwards?

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

Error Installing Homebrew - Brew Command Not Found [duplicate]

This question already has answers here:
Installing Homebrew on macOS
(24 answers)
Closed 2 years ago.
I've spent the bulk of my Friday trying to get the latest version of Ruby installed on my new MacBook Air (w/ Mountain Lion installed).
I have all the latest versions of XCode and command line tools. But I can't seem to get Homebrew to work! Here's a screenshot of where I keep getting stuck (I'm a new user, so can't embed this image).
As you can see I used the following to instal Homebrew:
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go/install)"
While there was a "warning" it seemed as though the installation worked:
Warning: /usr/local/bin is not in your PATH.
==> Installation successful!
Despite that, when I try to run "brew doctor" I received the following:
-bash: brew: command not found
Again, I'm trying to install homebrew, so i can instal the latest version of ruby -- I'm looking to learn to code in ruby, but kind of screwed if I can even get a development environment running! :)
The warning is telling you what is wrong. The problem is that brew is kept in /usr/local/bin
So, you can try /usr/local/bin/brew doctor
To fix it permanently alter your bash profile (.bashrc or .profile in your home directory) and add the following line:
export PATH=/usr/local/bin:$PATH
On Apple silicone it's
export PATH=/opt/homebrew/bin/:$PATH
Check XCode is installed or not.
gcc --version
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor
brew update
http://techsharehub.blogspot.com/2013/08/brew-command-not-found.html "click here for exact instruction updates"
nano ~/.profile
add these lines:
export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
save the file:
Ctrl + X then Y then Enter
then render the changes:
source ~/.profile
This was just happening to me, but none of the suggestions above worked. I changed directories ("cd ~/tmp") and suddenly the command
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
worked for me. Prior to changing directories I had been in a directory that is a Git repository. Perhaps that was interfering with the ruby and Git commands in the Brew install script.
You can run in terminal
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
then install https://github.com/robbyrussell/oh-my-zsh.
When those complate run i.e pico editor pico .zshrc and past those lines:
export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
remember use brew doctor :)
try this
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/linuxbrew/go/install)"
You can use this:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
to install homebrew.

Resources