brew installation for zsh?
Asked Answered
D

12

83

Hi I just followed the thoughtbot laptop setup for my Mac Mini Server running OSX Lion Server. I'm not sure that everything is installed correctly. Please advise.

I don't have a ~/.bash_profile or ~/.bashrc but i do have a ~/.profile

But here are contents for .zshrc since I use .zsh.

   1 # load our own completion functions
   2 fpath=(~/.zsh/completion $fpath)
   3 
   4 # completion
   5 autoload -U compinit
   6 compinit
   7 
   8 # automatically enter directories without cd
   9 setopt auto_cd
  10 
  11 # use vim as an editor
  12 export EDITOR=vim
  13 
  14 # aliases
  15 if [ -e "$HOME/.aliases" ]; then
  16   source "$HOME/.aliases"
  17 fi
  18 
  19 # vi mode
  20 bindkey -v
  21 bindkey "^F" vi-cmd-mode
  22 bindkey jj vi-cmd-mode
  23 
  24 # use incremental search
  25 bindkey "^R" history-incremental-search-backward
  26 
  27 # add some readline keys back
  28 bindkey "^A" beginning-of-line
  29 bindkey "^E" end-of-line
  30 
  31 # handy keybindings
  32 bindkey "^P" history-search-backward
  33 bindkey "^Y" accept-and-hold
  34 bindkey "^N" insert-last-word
  35 bindkey -s "^T" "^[Isudo ^[A" # "t" for "toughguy"
  36 
  37 # expand functions in the prompt
  38 setopt prompt_subst
  39 
  40 # prompt
  41 export PS1='[${SSH_CONNECTION+"%n@%m:"}%~] '
  42 
  43 # ignore duplicate history entries
  44 setopt histignoredups
  45 
  46 # keep TONS of history
  47 export HISTSIZE=4096
  48 
  49 # look for ey config in project dirs
  50 export EYRC=./.eyrc
  51 
  52 # automatically pushd
  53 setopt auto_pushd
  54 export dirstacksize=5
  55 
  56 # awesome cd movements from zshkit
  57 setopt AUTOCD
  58 setopt AUTOPUSHD PUSHDMINUS PUSHDSILENT PUSHDTOHOME
  59 setopt cdablevars
  60 
  61 # Try to correct command line spelling
  62 setopt CORRECT CORRECT_ALL
  63 
  64 # Enable extended globbing
  65 setopt EXTENDED_GLOB
  66 
  67 # RVM
  68 [[ -s '/Users/pma/.rvm/scripts/rvm' ]] && source '/Users/pma/.rvm/scripts/rvm'

Brew complains with brew doctor

[~] brew doctor
/usr/bin is in your PATH before Homebrew's bin. This means that system-
provided programs will be used before Homebrew-provided ones. This is an
issue if you install, for instance, Python.

Consider editing your .bashrc to put:
  /usr/local/bin
ahead of /usr/bin in your $PATH.

zsh:

[~] zsh --version
zsh --version
zsh 4.3.11 (i386-apple-darwin11.0)

So how can I ensure brew is installed correctly and remove the errors from brew doctor?

Drab answered 19/8, 2011 at 5:7 Comment(2)
What's the output of echo $PATHStefaniestefano
[~] echo $PATH /Users/pma/.rvm/gems/ruby-1.9.2-p290/bin:/Users/pma/.rvm/gems/ruby-1.9.2-p290@global/bin:/Users/pma/.rvm/rubies/ruby-1.9.2-p290/bin:/Users/pma/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/binDrab
S
86

Try setting this line in your .zshrc

export PATH=/usr/local/bin:$PATH
Stefaniestefano answered 19/8, 2011 at 5:11 Comment(1)
export PATH="/usr/local/bin:$PATH"Illaffected
S
151

This worked for me on macOS ARM (Apple M1):

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

and then:

export PATH="/opt/homebrew/bin:$PATH" >> ~/.zshrc
Smutch answered 4/1, 2021 at 19:55 Comment(4)
I confirm this works on M1 Mac. Adding the same line to .zprofile as suggested by the brew install did not work.Ribosome
@SeanDeNigris Interestingly, .zprofile did work for me!Norvan
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrcHypocycloid
@SeanDeNigris .zprofile instead of .zshrc also worked for me !Crossbones
S
86

Try setting this line in your .zshrc

export PATH=/usr/local/bin:$PATH
Stefaniestefano answered 19/8, 2011 at 5:11 Comment(1)
export PATH="/usr/local/bin:$PATH"Illaffected
B
27

This worked for me:

export PATH="/usr/local/bin:$PATH" >> ~/.zshrc
Bainbridge answered 7/10, 2014 at 21:40 Comment(0)
T
23

Not sure if this is late but you can simply run this to add Homebrew to your PATH:

eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
Twine answered 29/11, 2019 at 18:1 Comment(1)
I added this line to my ~/.zshrc and now I can run brew every time.Demagogic
S
11

I use ohmyzsh. Go to the directory

cd /usr/local/bin
brew doctor

You will notice it shows warnings like:

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
autoconf
automake
gdbm
gnupg
libgpg-error
libksba
libtool
libyaml
mongodb
node
pcre
pkg-config
zsh

You will have to run a command here:

brew link zsh

And that link it for me.

Semanteme answered 29/11, 2016 at 7:2 Comment(2)
THANK YOU for posting, you helped me out a lot! I used osx terminal forever then installed brew and all my packages weren't working. I had to run brew doctor to fix.Yogurt
/home/linuxbrew/.linuxbrew/bin/brew doctor in case brew command is not defined and you installed thereOrganicism
U
9

Following @Sajjad's answer did help but I had to run that command every time I started a new terminal which was

export PATH="/opt/homebrew/bin:$PATH" >> ~/.zshrc

I don't know much unix but what's going on here I believe is that we are appening export PATH="/opt/homebrew/bin:$PATH" part to our .zshrc file which at the root of our file structure at the end of the file.

So, I ran

nano ~/.zshrc

and added

export PATH="/opt/homebrew/bin:$PATH" 

at the end and it worked for all terminals from then on.

I am on the M1 if that is relevant

Unlatch answered 8/2, 2022 at 18:15 Comment(1)
Worked for me on Macbook Pro M2Hasseman
C
8

Open the ~/.zshrc file first line in file says

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

just comment out second line it will start working :)

Chain answered 20/12, 2018 at 8:46 Comment(0)
A
5

After installing Homebrew by the below command

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Run

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/atubasi/.zprofile

Then run

eval "$(/opt/homebrew/bin/brew shellenv)"

This will evaluate if your setup for Homebrew is working fine or not. You can run brew help to ensure that brew is defined in your zsh profile.

Anaesthetize answered 6/6, 2022 at 22:53 Comment(0)
K
1

For some reason none of the solutions here worked for me until I had to put both of the following two lines into my .zshrc file

export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"

export PATH="/home/linuxbrew/.linuxbrew/sbin:$PATH"

Then restart your zsh shell and it should work.

Kenney answered 6/11, 2022 at 17:11 Comment(0)
F
1

For permanent fix just execute the below command:

echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc
Furze answered 18/12, 2023 at 13:1 Comment(0)
S
0

Imac 2021 M1 Sonoma 14.4.1:

export PATH="/opt/homebrew/bin:$PATH" >> ~/.zshrc

Working for me!

Seine answered 21/5, 2024 at 16:2 Comment(0)
N
0

On macOS Sonoma, after installing brew, it told me what I needed to do:

(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/johndoe/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"

Partially-full output:

...
Unpacking objects: 100% (33/33), 5.60 KiB | 163.00 KiB/s, done.
From https://github.com/Homebrew/brew
 * [new tag]               4.0.29     -> 4.0.29
 * [new tag]               4.1.9      -> 4.1.9
 * [new tag]               4.2.14     -> 4.2.14
Switched to a new branch 'stable'
==> Updating Homebrew...
==> Downloading https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:49847c7a13f7094b211f6d0025900dd23716be07dac894a3d6941d7696296306
################################################################################################################################################# 100.0%
==> Pouring portable-ruby-3.3.3.arm64_big_sur.bottle.tar.gz
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.
==> Installation successful!

...
==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/johndoe/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
...
Neoterize answered 11/7, 2024 at 10:24 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.