'How to install homebrew on M1 mac
I just got a new Mac, the M1 Macbook pro and I am trying to install homebrew, but every time I finish installing it, it tells me that it was not written to the path, and then when I try the advised whatever to add to the path, nothing happens and the terminal or whatever does not recognize the command at all, as if it isn't installed.
This worked perfectly fine on my old Intel mac, and there is some step or whatever - I don't know anything, and I am tired and I don't understand how to install this at all, but hte path is supposed to be different for Apple silicon macs but nothing i read helps at all.
Solution 1:[1]
Homebrew installation on apple silicon, step by step:
- Open a terminal window (it should be zsh)
- Run this command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
In my case, installation show me errors, I just installed again, and then show: Installation successful!, and warning: /opt/homebrew/bin is not in your PATH
- Then create .zshrc on home directory (If it was not created yet). Just run on terminal:
touch ~/.zshrc
Then open it to edit with TextEdit (Is a hidden file. You can show hidden files with shift + command + . )
Add this line at the end of .zshrc
export PATH=/opt/homebrew/bin:$PATH
- Run this command in terminal to make this available:
source ~/.zshrc
- Now just run this command to be sure that everything is working:
brew help
This works for me to path homebrew permanently.
Or do:
- Add Homebrew to your PATH in ~/.zprofile:
echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> ~/.zprofile
eval $(/opt/homebrew/bin/brew shellenv)
Solution 2:[2]
Seems Touch, source and export not required now.
Run the below command in terminal
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
and follow the instructions showing in terminal itself. shows as follows:
==> Next steps:
Run these two commands in your terminal to add Homebrew to your PATH:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/xxx/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
Then, brew help
Solution 3:[3]
open the terminal and copy below command
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
create new empty file with touch
touch .zshrc
now open the file with vim editor
vim .zshrc
now enter i to start edit mode and write
export PATH=/opt/homebrew/bin:$PATH
then press esc and type :wq
now we setup brew successfully for permanently to test enter
brew or brew help
Solution 4:[4]
Go to Homebrew and get the install command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
When requsted in the Terminal press 'return' to finish installation
After installation, the Terminal generates the next commands to be executed:
==> Next steps: Run these two commands in your terminal to add Homebrew to your PATH: echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/$yourdevicename/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)" Run brew help to get started - Further documentation: https://docs.brew.sh
Solution 5:[5]
Go To the home brew webpage
copy the script provided under Install Homebrew
Open Terminal via spotlight search
Then open the terminal in the using the spotlight search by pressing the command + spacebar
now in the terminal paste the script which was copied from the homebrew site
it will ask to click return button after some time so don't worry after successful installation the brew won't work as for M1 Chip MacBook air.
It will show some warning for the path i.e. warning: /opt/homebrew/bin is not in your PATH
==>Now on the same terminal we will create the file .zshrc in the home directory
So Run the command to create this directory i.e.
touch .zshrc
Now we will open the home directory
To open home directory we will open the finder from the dock and make sure its the active application
now in the finder app we will press button to open the home directory i.e. command+shift+H
After this finder will open the home directory
Now since the .zshrc is a hidden file as we created it using the terminal above
Now to access the hidden file press the button i.e. shift + command + .
After this locate the .zshrc file and click to edit with Text Editor option
Set the path in .zshrc file
Now at the end of the line paste this -
export PATH=/opt/homebrew/bin:$PATH
Now we will make this file available
So type paste this code in the terminal
source ~/.zshrc
After this command run one more command on the terminal to check if the howebrew is working fine
brew
On typing this you will get to know that home brew is now working!!
Now do what ever you want to do using brew either install git or any other things which you want....
Have a Good Day Guys!!
Solution 6:[6]
export PATH=/opt/homebrew/bin:$PATH
put this in a .zshrc folder in your default home directory. I just had this same problem. Good luck buddy
Solution 7:[7]
Also, you can check this short article out and doing it using aliases.
Solution 8:[8]
If you are getting the intel chip error
xcrun: error: unable to load libxcrun (dlopen(/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib, 0x0005): tried: '/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/libxcrun.dylib' (no such file)).
then you have to fix your command line tools (CLT). What I did is the following (solution from here):
What I suggest is to uninstall the command line tools (CLT) and re-install them the official way (source).
So do (source):
sudo rm -rf /Library/Developer/CommandLineTools
check it uninstalled, you should get an output as follows:
xcode-select -p
output
xcode-select: error: unable to get active developer directory, use `sudo xcode-select --switch path/to/Xcode.app` to set one (or see `man xcode-select`)
then install the command line tools (CLT) again:
xcode-select --install
then agree to it and it should download after a couple of minutes. The download should take some time. For me ~13mins.
After that your issues with PyCharm, git, brew and likely other tools will be resolved.
After you have that resolved -- which was causing me issue when trying to install brew -- do what the top answer here recommends: https://stackoverflow.com/a/67271753/1601580 which in a summary is run the bash install of brew and make sure it is in your PATH env variable properly.
Solution 9:[9]
After Installing brew
Go to root folder by opening the terminal.
type: vim .zshrc if exist. Type i to start editing the .zshrc file. add line
export PATH=/opt/homebrew/bin:$PATH
After editing, press esc and save using :wq
Then run command
exec zsh
And voila, brew is ready..
Thanks, Let me know if it helps.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
