Background:
macbook pro
chip: m1
os ver: 12.2.1 (21D62)
Problem
I previously had homebrew installed on this machine via curl [found on homebrew's homepage].
I was having issues installing pyenv and came across this guide.
Step 1 was somewhat successful:
pyenv got installed
I was able to add the exports and evals to my .zshrc file:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
I noticed the following after closing and reopening iterm2:
I was getting a pyenv command not found error coming from .zshrc
The brew command was also not found
I was still able to use the pyenv command, despite the initial error when opening a new terminal session.
Logs
My install logs (all commands taken from above link)
thleo ~ /Users/thleo > ~ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
Cloning into '/Users/thleo/.pyenv'...
remote: Enumerating objects: 21712, done.
remote: Counting objects: 100% (470/470), done.
remote: Compressing objects: 100% (346/346), done.
remote: Total 21712 (delta 336), reused 194 (delta 107), pack-reused 21242
Receiving objects: 100% (21712/21712), 4.37 MiB | 1.17 MiB/s, done.
Resolving deltas: 100% (14676/14676), done.
thleo ~ /Users/thleo > ~ cd ~/.pyenv && src/configure && make -C src
gcc -fno-common -c -o realpath.o realpath.c
gcc -dynamiclib -dynamic -undefined dynamic_lookup -o ../libexec/pyenv-realpath.dylib realpath.o
thleo ~ thleo/.pyenv - (master) > ~ arch
arm64
thleo ~ thleo/.pyenv - (master) > ~ which brew
/opt/homebrew/bin/brew
thleo ~ thleo/.pyenv - (master) > ~ brew --version
Homebrew 3.5.4
Homebrew/homebrew-core (git revision e2e2cd1d5f0; last commit 2022-07-07)
Homebrew/homebrew-cask (git revision 63bdf4e642; last commit 2022-07-07)
thleo ~ thleo/.pyenv - (master) > ~ vi ~/.zshrc
thleo ~ thleo/.pyenv - (master) > ~
Behavior after install:
On launching new session in terminal:
Last login: Fri Jul 8 16:18:29 on ttys005
/Users/thleo/.zshrc:61: command not found: pyenv
thleo ~ /Users/thleo > ~ brew
zsh: command not found: brew
thleo ~ /Users/thleo > ~ pyenv --version
pyenv 2.3.2-1-g207f33fc
Question(s):
why is brew not found? I can't seem to find folders related to homebrew anywhere on the machine [searched via finder]
why is there a command not found: pyenv error when I can clearly use the command?
Related
I need to install a newer version of a dependency via Brew than what is contained in the Travis CI image. Running brew update adds more than 100 seconds to every build job, so I'd like to find a way to cache the installation, or at least cache the Bottle and Formula.
It seems like there should be a simple recipe for caching the Bottles and Formulas from Brew, but so far I have not found that recipe.
To be specific, I'm using pyenv on TravisCI and for the build jobs that runs tests with Python 2.6 I need pyenv to be the latest (1.2.4), since get_pip fails on earlier versions due to recent changes on PyPI.
I added a conditional to my .travis.yml and it works fine:
if [[ "$pyver" == 2.6 ]]; then
brew upgrade pyenv &>/dev/null
fi
However, the command takes a while to run. I've split out the upgrade command and timed it:
time brew update
time brew upgrade pyenv
The brew update takes more than 100 seconds, the brew upgrade takes 10 seconds.
That finding led to the idea to cache the Bottle and Formula and on every subsequent build run:
HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade pyenv
There's a question on how to cache Brew sources. That works fine.
cache:
directories:
- "$HOME/Library/Caches/Homebrew"
In $HOME/Library/Caches/Homebrew, I find the bottle cached:
pyenv-1.1.5.sierra.bottle.tar.gz
pyenv-1.2.4.sierra.bottle.tar.gz
However even with the bottle cached, running HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade pyenv doesn't succeed, presumably because the updated formula is not cached. The command yields:
Error: pyenv 1.1.5 already installed
I added caching of the formula:
cache:
directories:
- "$HOME/Library/Caches/Homebrew"
- /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
and implemented the following algorithm:
Run HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade pyenv to upgrade pyenv using the latest cached formula/bottle.
Test if pyenv >= 1.2.4 is installed. If the pyenv 1.2.4 formula and bottle were cached, it will be installed in step (1) without brew update having been run.
If pyenv >= 1.2.4 was not cached, then run brew upgrade pyenv and save the cached bottle and formula.
and the following script:
function ver { printf "%03d%03d%03d" $(echo "$1" | tr '.' ' '); }
HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade pyenv &>/dev/null
# Update brew and upgrade pyenv if necessary
if [ $(ver $(pyenv --version | cut -d ' ' -f2)) -lt $(ver 1.2.4) ]; then
brew upgrade pyenv &>/dev/null
fi
However, I question whether it's a good idea to cache /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core. The examples in the Travis CI documentation are always caching directories under $HOME. It seems like I might experience problems when Travis updates the image. Does Travis CI delete the branch caches after the image is updated? If not, it seems like I would need to do that manually.
Is there a better way? It seems like Travis CI should offer an easy way to cache Brew formula and bottles.
Should I not bother with Brew and just install pyenv from the source?
I cached the brew formula under $HOME by copying the file on the first build:
cache:
directories:
- "$HOME/Library/Caches/Homebrew"
[...]
before_install:
- |
if [ "$TRAVIS_OS_NAME" = osx ]; then
# Pyenv >= 1.2.4 is needed with Python 2.6
if [[ "$pyver" == 2.6 ]]; then
# Upgrade pyenv and save formula/bottle in cache.
formula=$(brew --repository)/Library/Taps/homebrew/homebrew-core/Formula/pyenv.rb
formula_cached=$(brew --cache)/pyenv.rb
if [[ ! -f $formula_cached ]]; then
brew upgrade pyenv &>/dev/null
cp $formula $formula_cached
else
HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade $formula_cached
fi
fi
I'm trying to install memcached with older versions (ex: 1.4.5) but I'm not sure how to do it.
brew install memcached installs the latest.
I also tried brew install memecached1.4.5 but it didn't work.
Usually, you can check if multiple versions are available and you can specify the version with #. e.g. brew install package#2.8
$ brew info memcached
memcached: stable 1.4.24
High performance, distributed memory object caching system
https://memcached.org/
Conflicts with:
mysql-cluster (because both install `bin/memcached`)
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/memcached.rb
...
If is not available the version you want you can go to the repo, and check the history
cd "$(brew --repo homebrew/core)"
git log master -- Formula/memcached.rb
Then you can find the commit you are looking for
commit 5ec463decefeaab3d1825b923ad2dbee73ffc6dc
Author: Adam Vandenberg <flangy#gmail.com>
Date: Fri Apr 9 21:19:48 2010 -0700
Update memcached to 1.4.5
Checkout that version and install:
cd "$(brew --repo homebrew/core)" && git checkout 5ec463decefeaab3d1825b923ad2dbee73ffc6dc
HOMEBREW_NO_AUTO_UPDATE=1 brew install memcached
Once you get the version installed:
git checkout master # bring brew back to its latest version
brew pin memcached # [optional] prevent formula from updating
and, that's it!
I would do
brew unlink memecached
brew install memecached#1.4.5
brew link memecached#1.4.5 --force
A more expanded version of the good answer from Adrian is also here on SO.
https://stackoverflow.com/a/53766019/3794873
One thing to keep in mind is that if you are installing an older Formula the Homebrew API/methods may have changed since that time so you should brew edit appFormula against the current version and compare to the brew edit app#your.version if you encounter any errors trying to brew install app#your.version after the brew extract command in the answer linked.
2021 update:
$ curl https://raw.githubusercontent.com/Homebrew/homebrew-cask/<commit-hash>/Casks/<FORMULA>.rb > $(find $(brew --repository) -name <FORMULA>.rb)
$ brew reinstall <FORMULA>
You can find the cask or formula file URL here and the commit message should describe the file version to grab the URL for.
https://github.com/Homebrew/homebrew-core/commits/master/Formula/<formula>.rb
https://github.com/Homebrew/homebrew-cask/commits/master/Casks/<cask>.rb
Credit: https://remarkablemark.org/blog/2017/02/03/install-brew-package-version/
Sharing an interactive oneliner I made for myself of Adrian's answer now:
It does a simple parsing, depending only on "/blob/" in the github URL, of "From" in brew info, and does a bash select of commit from git log.
brew install can be replaced with brew reinstall as needed.
Tested (for cask "name=powershell") in bash 5.1 (from macports ;P) and env -i /bin/bash 3.2 on macOS (High Sierra) 10.13.6 against brew 3.3.11. (I might have done some tap'ing the other day.)
(name= && { [[ $name ]]||read -ep "Name: " name;} && [[ $(brew info "$name"|sed -Ene'/^From: (.*)/s//\1/p') =~ ([^/]*)/blob/([^/]*)/([^/]*)/([^/]*) ]] && V=("${BASH_REMATCH[#]:1}") && N=(repo current dir file) && for s in ${!N[#]};do eval "${N[s]}=\${V[s]}" && declare -p >&2 "${N[s]}";done && cd "$(brew --repo "${repo//-//}")" && IFSO="$IFS" && IFS=$'\n' && select line in $(git log --oneline master -- "$dir/$file");do IFS="$IFSO" && commit=($line) && break;done && set -x && git checkout "$commit" && HOMEBREW_NO_AUTO_UPDATE=1 brew install "$name" && git checkout master)
Skål, salud, cheers!
I used to have Homebrew installed, but then at some point it broke, so I tried reinstalling it.
I tried running:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
It gave:
-e:70: warning: Insecure world writable dir /usr/local 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 don't know why it says it is installed, running brew gives "zsh: command not found: brew")
So I tried running that:
zsh: command not found: brew
Then I tried running it without brew clean-up. Which executed. I re-ran:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
It starts downloading and installing until it gets to this point:
Downloading and installing Homebrew...
remote: Counting objects: 226839, done.
remote: Compressing objects: 100% (59610/59610), done.
remote: Total 226839 (delta 165997), reused 226815 (delta 165979)
Receiving objects: 100% (226839/226839), 52.14 MiB | 135.00 KiB/s, done.
Resolving deltas: 100% (165997/165997), done.
From https://github.com/Homebrew/homebrew
* [new branch] master -> origin/master
warning: unable to access 'bin/.gitattributes': Permission denied
error: unable to create file bin/brew (Permission denied)
fatal: Could not reset index file to revision 'origin/master'.
Failed during: git reset --hard origin/master
Tried adding sudo:
sudo ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Gives:
Don't run this as root!
I don't know where to go from here. Can someone help me?
Did you restart your terminal after installing zsh? brew is possibly not loaded for zshell. Also you need to add usr/local/ to your $path in .zshrc zsh configuration file should be in the in root ~/.zshrc
I'm having a problem re-installing homebrew. I am running Mavericks
It started with me trying to install express.js. Homebrew had been installed on my mac for quite some time, never had any trouble with it. I used sudo npm install -g express, but when I ran express --version, I got command not found. Eventually, I found a possible solution online, and just tried to reinstall npm with brew remove npm and brew install npm. Again, I ran into errors (Unfortunately, I didn't save the exact errors) I used brew doctor to try and figure it out, looked up a ton of tutorials and mucked around with homebrew, and I guess I broke something.
Now, I figure I should just try and reinstall homebrew.
I run the install command for homebrew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
It returns this message:
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
So, I run
rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
This returns:
-bash: brew: command not found
I try running the install command again, and this time, it doesn't tell me homebrew is already installed.
So again, I run the install command for homebrew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
And now I get this:
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
Password:
==> Downloading and installing Homebrew...
remote: Counting objects: 136, done.
remote: Total 136 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (136/136), 10.37 MiB | 1.53 MiB/s, done.
Resolving deltas: 100% (44/44), done.
From https://github.com/Onomanatee/portfolio_Yuri_Legiest
* [new branch] master -> origin/master
HEAD is now at c253261 Commit4
==> Installation successful!
==> Next steps
Run brew doctor before you install anything
Run brew help to get started
Running brew doctor or brew help , however, results in
-bash: brew: command not found
I really don't know how to fix this. And why is the brew installer referring to a repository I used as a test for a little web project? (right above Installation succesful!)
How do I fix this path issue? I can't use brew command and I think I previously symlink to wrong location.
Master:~ shaunstanislaus$ ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
Press enter to continue
==> Downloading and Installing Homebrew...
remote: Counting objects: 82368, done.
remote: Compressing objects: 100% (39323/39323), done.
remote: Total 82368 (delta 56782), reused 65301 (delta 42220)
Receiving objects: 100% (82368/82368), 11.68 MiB | 1.59 MiB/s, done.
Resolving deltas: 100% (56782/56782), done.
From https://github.com/mxcl/homebrew
* [new branch] master -> origin/master
HEAD is now at 2ea1a0e smpeg: depends on gtk
==> Installation successful!
You should run `brew doctor' *before* you install anything.
Now type: brew help
Master:~ shaunstanislaus$ brew doctor
-bash: /usr/local/bin/brew: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
Master:~ shaunstanislaus$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/shaunstanislaus/Library/Application Support/GoodSync:/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/Users/shaunstanislaus/.ec2/bin:/Users/shaunstanislaus/.rvm/bin
/usr/local/bin/brew: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
Not everyone keeps the default system version of ruby. Many will rename this file and use the MacPorts ruby, or compile it by hand, in which case it may be in a different location.
I recommend changing this so that it will look for the ruby executable in a different location if it's not in the default.
Visit http://linguisticlogic.wordpress.com/2010/11/27/homebrew-mac-osx-and-ruby/
just doing
sudo ln -s /opt/local/bin/ruby /usr/bin/ruby
may work !!!