Homebrew doesn't stay installed? M1 Macbook - macos

I've upgraded to an M1 Macbook Pro and need to reinstall all of the goodies that I use regularly.
This includes Homebrew.
I have been to the official Homebrew site and done what they suggest:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
It then suggests to run
echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/username/.bash_profile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/username/.bash_profile
eval "$(/opt/homebrew/bin/brew shellenv)"
To keep it within the path for future use - I would think this was the thing that keeps it being reusable when you restart/get a new Terminal
And this works great. I can then use brew install xxx after installation to install whatever packages I require.
The issue comes when I get a new Terminal or restart etc. I go to perform another brew install and I get the annoying
-bash: brew: command not found
Is there something that I've not done after the initial install that means my Mac doesn't remember it's installed brew?

I was running into the same issue as you. My issue was my terminal was set to bash instead of zsh by default. I had to run chsh -s /bin/zsh and followed the top answer on another post, which is similar if not identical to the steps you include in your question. I restarted my terminal and ran through brew help worked!

Related

How to run the Homebrew installer under Rosetta 2 on M1 Macbook

I'm on the M1 MacBook.
This is the error when I try to install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Homebrew is not (yet) supported on ARM processors!
Rerun the Homebrew installer under Rosetta 2.
If you really know what you are doing and are prepared for a very broken experience you can use another installation option for installing on ARM:
https://docs.brew.sh/Installation
So how do I "Rerun the Homebrew installer under Rosetta 2."?
Got an answer from a developer in the Homebrew github https://github.com/Homebrew/brew/issues/9173
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Use this to install packages:
arch -x86_64 brew install <package>
If you have not yet installed Rosetta 2 to emulate Intel CPUs on ARM Macs, you will get the error arch: posix_spawnp: /bin/bash: Bad CPU type in executable. Prompt a Rosetta 2 installation with:
softwareupdate --install-rosetta
I have two instances of brew installed, the Intel version that runs using Rosetta2 and which installs to /usr/local/bin and the Arm version that runs natively and installs to /opt/homebrew/bin. Now it is all working, I do not have to start iTerm using Rosetta.
I have these aliases to reach the two versions.
ibrew='arch -x86_64 /usr/local/bin/brew'
mbrew='arch -arm64e /opt/homebrew/bin/brew'
I have the native version in my path first:
path=( /opt/homebrew/bin /opt/homebrew/opt /usr/local/bin /usr/bin /bin /usr/sbin /sbin /Library/Apple/usr/bin )
Now I can try mbrew search and mbrew install. If they work, I am good to go with a native program. For example:
mbrew install ag
If brew fails I try building from source, with verbose output, e.g.
mbrew install -sv rust
Be warned, this takes a while and may still fail.
If it still fails, (and mbrew install -sv go results in a segmentation fault for me) I have two choices. Use ibrew search and ibrew install to get the Intel build instead, or examine the verbose output and look for problem dependencies. In some cases an install -s on the dependencies is enough to get the native brew to work.
I must stress that native brew always prints this warning
Warning: You are running macOS on a arm64 CPU architecture.
We do not provide support for this (yet).
Reinstall Homebrew under Rosetta 2 until we support it.
So proceed at your own discretion.
For completeness, and assuming you have iTerm2, Rosetta2 and the Xcode command line tools installed, I did this to install brew under Rosetta (with credit to all those who have posted on this page before me):
Copy the installed iTerm2.app application to iRosetta2.app
Press command+I to Get Info for iRosetta.app, click Open Using Rosetta2
Run iRosetta2 and use this command from https://brew.sh
Like so
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)
alias ibrew='arch -x86_64 /usr/local/bin/brew' # put this in ~/.zshrc
And I did this to install native brew, taken from other contributors to Stack Overflow and the Homebrew alternative installation site, using iTerm2 without Open Using Rosetta2
mkdir ~/homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
sudo mv ~/sudo mv homebrew /opt
mbrew='arch -arm64e /opt/homebrew/bin/brew' # for .zshrc
export PATH="/opt/homebrew/bin:/opt/homebrew/opt:$PATH" # also for .zshrc
Edit
Time has passed and I have changed the architecture to arm64e following Fernando García Redondo observation. Now the warning about Arm architecture not supported has gone and Rust and Go install without problems and without compiling from source. I assume the good people at Homebrew have been working hard over Christmas. Thanks!
Edit Feb 21
The Homebrew team have announced that they support Apple silicon. So I wondered if I could delete my aliases and just use brew to install for Apple silicon. The short answer is no! if you run brew from /usr/local without the arch -x86_64, it complains that /usr/local is reserved as the Intel default prefix and using /opt/homebrew is required. So I will retain my two aliases and try mbrew first and only use ibrew if the native brew fails.
Another option is by going into your applications in Finder, select Terminal and press ⌘+I and check the "Open using Rosetta" option.
Sorry if the formatting is off, first time posting a solution.
The easiest way to run Homebrew is with Rosetta 2.
1. Duplicate Your Favourite Terminal for Rosetta
Find your favourite terminal, right-click to duplicate it, and rename it for easier identification. In this example, I'm using the default Terminal app on Big Sur 11.2.1.
Right-click the Terminal Rosetta and go to Get Info to check the Open using Rosetta option.
2. Install Homebrew
Open the rosetta terminal and run the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Running this command will ask you for the password, and then it will provide you with the information of what all it will install and which new directories it will create.
3. Using Homebrew
Once HomeBrew is installed, you can start using it to install your required packages into the M1 Mac.
Run the following command to get brew help:
brew help
To install a package, you can run the following command:
brew install packagename
That’s all about installing and getting started with Homebrew on Apple M1 Macs.
EDIT: Thanks all! Upvote to help other devs! Homebrew 3.0.0 now officially supports Apple Silicon (https://brew.sh/2021/02/05/homebrew-3.0.0/)
After I installed Rosetta, I added an alias so I can use brew install <package> as I would normally.
alias brew='arch -x86_64 brew'
I agree with everyone else in that you need to add the arch -x86_64 in front of the original command so thought to include that alias to help anyone finding this thread in the future
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" worked on my new M1 Mac
Do below
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
alias brew='arch -x86_64 brew'
brew install azure-cli
now try az login. you are good to go
You can change the setting of Terminal to launch it using Rosetta.
Go to your Application/Utilities folder, right click on the Terminal App and check the tick box 'Open using Rosetta'
But to be honest, I have Homebrew installed without Rosetta. Just removed the x86 version yesterday and installed a fresh version without Rosetta.

Mac - Can't Install HomeBrew because Curl is Missing

I tried to install homebrew onto my mac, but I couldn't because curl wasn't found. I typed:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
This returned this error:
-bash: curl: command not found
So, I tried to install curl but apparently to install curl, I need to use curl? This is what I found:
Run in Terminal app:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" <
/dev/null 2> /dev/null
Run:
brew install curl
Done! You can now use curl.
However, this uses curl to install curl, so it gives the same error message: -bash: curl: command not found
TL;DR, how do I install curl on mac without using curl
I solved the problem!
To use bash on mac:
Go to terminal ––> preferences
Click on Shells open with: and set it to Command (complete path)
Enter one of the following:
/bin/bash
/bin/csh
/bin/zsh
/bin/zsh-4.0.4 (Mac OS X 10.2.8 or earlier)
/bin/zsh-4.1.1 (Mac OS X 10.3 or later)
/bin/ksh (Mac OS X 10.4 or later)
/bin/ksh worked for me
Source
I thought I broke my curl symlink somehow too, and somewhere in there I ran into your same issue, where no command would work. Somewhere in this mess, I fixed it.
https://brew.sh/
The main website requires you to install wget, maybe it gets deleted when you uninstall homebrew.
Regardless I found a way to install it using Ubuntu commands.
https://xmrig.com/docs/miner/build/ubuntu
but ran into an issue where I had to download cmake from the developer website and add it to the path in it's menu options on Mac OS X 10.11 to compile and run my program as ./program instead of program, then I installed macports(opened a new terminal window), and installed hwloc with macports, to no avail, just getting totally different errors.
I've also tried to add curl as an alias of curl into the bash profile and it recognized the error after I used this;
https://github.com/Homebrew/homebrew-core/issues/5084
However, I forgot I have an identical computer that is working just fine, but when I run "which curl", in the working computer, I get /usr/bin/curl, instead of /usr/local/bin/curl, so I ran
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin/curl"
I'm still getting the error, so I used vim, to sudo edit the /etc/paths file by using
sudo vim /etc/paths
i for edit
esc to exit edit mode
:x to save
Restart Terminal
Still getting a 403 SNI Error cannot download Python 3.9
rm -rf /opt/local/bin/curl
rm -rf /usr/local/bin/curl
which curl finally returns the correct path, /usr/bin/curl
exit
Restart Terminal
Still same error so I removed /usr/bin/curl from /etc/paths, and export file. Also deleted the bash profile, as the working computer doesn't return one, and...still the same error, so I conclude that "curl is not in path" should be ignored.
I did get brew doctor to return with no errors.
brew upgrade curl
curl not installed
brew install curl
403 Error SNI is required.
brew upgrade openssl
openssl 1.1.1j already installed
In my case, I made a mistake while editing my $PATH.
I would recommend looking at all your ~/.bash_profile and ~/.zshrc.
Remove ALL code related to $PATH. Carefully add things back in.

Installing vim with homebrew assistance

I tried to install YouCompleteMe on Mac for vim, but I've been using the system vim which is version 7.3. I tried to update my vim using homebrew by typing brew install vim and everything seemed to be fine.
When I type vim I still see the system vim loading (version 7.3).
I feel like I'm missing a step that's keeping me from using the updated vim I got from homebrew. Does anyone know what I'm missing?
For reference when I type which vim I get the following output /usr/bin/vim. Any help would be greatly appreciated.
Just install vim via homebrew:
brew install vim
Then restart your shell:
exec -l $SHELL
And check the version:
$ vim --version|head -n 1
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 9 2016 19:07:39)
You should probably have done brew install vim --with-override-system-vi. This will replace default vim path.
You're loading your system vim first, as you can see by which vim returning /usr/bin/vim instead of /usr/local/bin/vim.
/usr/local/bin is homebrew's path.
Make sure that your path lists /usr/local/bin before /usr/bin:
/usr/local/bin:/usr/bin
This will allow homebrew's vim to be sourced before the system vim.
To view your path:
echo "$PATH"
Rather than reinstalling vim you can move your current vim to vim73 (or something similar).
First check if /usr/local/bin is present in PATH environment variable. Doing echo $PATH on your terminal should do that.
Install vim with homebrew if you haven't already.
brew install vim
Then move your current vim installation.
mv /usr/bin/vim /usr/bin/vim73
Run which vim to confirm. It should say /usr/local/bin/vim.
brew install vim --with-override-system-vi (missing the with-)
echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
Run this command and it will be fixed.

Mac: How to fix sudo command failure?

I am writing script to run SU commands programmatically to do various operations. But, All the commands created through my program is not working. Then, i tried those commands in Terminal (Mac os x) by typing it, but it gives the following result,
sudo: apt-get: command not found
Could someone please advise me, why is this error coming up, how can i make these working?
Homebrew installs the stuff you need that Apple didn’t.
install ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
e.g :
$ brew install wget
There's also MacPorts, and fink -- I also have homebrew, but also keep the others around for when I encounter things that one system has that the other doesn't.
apt-get is unique to the Debian based operating systems. If you want a package manager for OSX, may I suggest homebrew
http://brew.sh

How do I update zsh to the latest version?

I recently switched to zsh on my Terminal.app on my OS X machine successfully. The version number of zsh is 4.3.11.
If you're using oh-my-zsh
Type omz update in the terminal
Note: upgrade_oh_my_zsh is deprecated
If you have Homebrew installed, you can do this.
# check the zsh info
brew info zsh
# install zsh
brew install --without-etcdir zsh
# add shell path
sudo vim /etc/shells
# add the following line into the very end of the file(/etc/shells)
/usr/local/bin/zsh
# change default shell
chsh -s /usr/local/bin/zsh
If you're not using Homebrew, this is what I just did on MAC OS X Lion (10.7.5):
Get the latest version of the ZSH sourcecode
Untar the download into its own directory then install: ./configure && make && make test && sudo make install
This installs the the zsh binary at /usr/local/bin/zsh.
You can now use the shell by loading up a new terminal and executing the binary directly, but you'll want to make it your default shell...
To make it your default shell you must first edit /etc/shells and add the new path. Then you can either run chsh -s /usr/local/bin/zsh or go to System Preferences > Users & Groups > right click your user > Advanced Options... > and then change "Login shell".
Load up a terminal and check you're now in the correct version with echo $ZSH_VERSION. (I wasn't at first, and it took me a while to figure out I'd configured iTerm to use a specific shell instead of the system default).
As far as I'm aware, you've got three options to install zsh on Mac OS X:
Pre-built binary. The only one I know of is the one that ships with OS X; this is probably what you're running now.
Use a package system (Ports, Homebrew).
Install from source. Last time I did this it wasn't too difficult (./configure, make, make install).
A simple script or execute following commands in terminal
# 1. download (currently the latest version is 5.8) and extract
wget https://sourceforge.net/projects/zsh/files/latest/download -O ./zsh-latest.tar.xz
mkdir zsh-latest
tar -xf zsh-latest.tar.xz -C zsh-latest --strip-components=1
cd zsh-latest
# 2. config, build, install
./configure
make -j4
sudo make install
which zsh
PS: If you fail to build, it probably due to missing necessary libraries. Just install libraries as the error message suggests. E.g, I didn't have ncurses:
sudo apt install ncurses-devel # for Ubuntu
sudo yum install ncurses-devel # for CentOS/Redhat
omz update gave me following error:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
This is an issue with git, where after upgrading to Mac OS Ventura (13.0.1). git command gave me above error.
Solution:
Download and install the 'Command Line Tools' package to fix 'git'
xcode-select --install
This will pop a dialogue box. Select "Install".
More details here: https://apple.stackexchange.com/a/254381
omz update worked successfully after this for me
I just switched the main shell to zsh. It suppresses the warnings and it isn't too complicated.

Resources