Command Brew not Found? - terminal

I installed homebrew with ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" on Mac but when I try to install python3 with
brew install python3
I get error of
zsh: command not found: brew
I know brew is installed but maybe I haven't done it in right location? I am in a directory of a folder in my desktop
Output of echo $PATH | tr ':' '\n'
/usr/local/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
Thanks for the help in advance

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/neerajvishwa/.zprofile
type this in terminal - it worked for me

If using Macbook M1 chip run this after installation done
eval $(/opt/homebrew/bin/brew shellenv)

I use the MacBook Air M1 and I have the same issue, where I need to run eval $(/opt/homebrew/bin/brew shellenv) every time I open the terminal to use brew.
I reran the 2 commands we are supposed to run after installing homebrew. (You need to replace [username] by your Mac user name)
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/[username]/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
I even completely rebooted my Mac to make sure the fix was permanent.

Related

Brew stops working after terminal session is closed

I have installed Brew in MACOS Monterey with the following commands.
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
eval "$(homebrew/bin/brew shellenv)"
brew update --force --quiet
chmod -R go-w "$(brew --prefix)/share/zsh"
I have tested it after the install, and it works, however closing the terminal session and opening it again causes terminal to say that the command brew is not found after running it. I can still see the homebrew directory, so Im guessing its in the wrong place for terminal to run it.
The only supported method to install brew is found on brew.sh:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Ok I was able to fix the issue by adding the PATH to the .bash_profile file.

Unable to install Ruby on Ubuntu

I'm trying to install Ruby 2.6.1 on Ubuntu but keep coming across this error.
Have tried uninstalling Ubuntu, googling the problem, running in administrator mode, downloading a different version.
This is the error:
:~$ rvm install 2.6.1
Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-2.6.1.tar.bz2
Checking requirements for ubuntu.
Installing requirements for ubuntu.
mkdir: cannot create directory ‘/usr/share/rvm/log/1625135668_ruby-2.6.1’: Permission denied
tee: /usr/share/rvm/log/1625135668_ruby-2.6.1/update_system.log: No such file or directory
Updating system..jaydene password required for 'apt-get --quiet --yes update':
Sorry, try again.
jaydene password required for 'apt-get --quiet --yes update':
..
Error running 'requirements_debian_update_system ruby-2.6.1',
please read /usr/share/rvm/log/1625135668_ruby-2.6.1/update_system.log
Requirements installation failed with status: 1.
:~$
you can use a gorails website to checkout ruby on rails installation. And ruby installs version as per dependencies on your system. If it's not founding 2.6.1 it will install next supported version for ex. 2.6.7.
check this website: https://gorails.com/setup/ubuntu/21.04
Check this: How do I install Ruby 1.9.3 on Ubuntu without RVM? but SO says to avoid link answers so here is the script:
#!/usr/bin/env bash
# -- this really is the only solution that worked for me on snap :/
ruby -v
if ! command -v ruby &> /dev/null
then
echo "Going to try to install ruby (ideally 3.1.2)"
# - install rebenv (following ruby-build really is needed eventhough it doesn't look like it)
mkdir -p ~/.rbenv
cd ~/.rbenv
git clone https://github.com/rbenv/rbenv.git .
# if $HOME/.rbenv/bin not in path append it, otherwise don't change it
echo $PATH | tr ':' '\n' | awk '{print " " $0}';
if [[ ":$PATH:" != *":$HOME/.rbenv/bin:"* ]]; then
echo "might want to put $HOME/.rbenv/bin in your path"
export PATH="$HOME/.rbenv/bin:$PATH"
# echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc.lfs
fi
eval "$(rbenv init -)"
rbenv -v
# - install ruby-build, odd, this really is needed for ruby to install despite it not looking like ruby build is need at the bottom
mkdir -p ~/.ruby-build
cd ~/.ruby-build
git clone https://github.com/rbenv/ruby-build.git .
# if $HOME/.ruby-build/bin not in path append it, otherwise don't change it
echo $PATH | tr ':' '\n' | awk '{print " " $0}';
if [[ $PATH != *"$HOME/.ruby-build/bin"* ]]; then
echo "might want to put $HOME/.ruby-build/bin in your path"
export PATH="$HOME/.ruby-build/bin:$PATH"
# echo 'export PATH="$HOME/.ruby-build/bin:$PATH"' >> ~/.bashrc.lfs
fi
ruby-build --version
# - install ruby without sudo -- using rbenv
mkdir -p ~/.local
# ruby-build 3.1.2 ~/.local/
rbenv install 3.1.2
rbenv global 3.1.2
fi
ruby -v
# - Original Prover doesn't work on SNAP
# Proverbot's way to install ruby
# # First, install Ruby, as that is for some reason required to build the "system" project
# git clone https://github.com/rbenv/ruby-build.git ~/ruby-build
# mkdir -p ~/.local
# PREFIX=~/.local ./ruby-build/install.sh
# ~/.local/ruby-build 3.1.2 ~/.local/
# ref: https://superuser.com/questions/340490/how-to-install-and-use-different-versions-of-ruby/1756372#1756372

How to Install Homebrew on Windows WSL Ubuntu, and fix "zsh: brew command not found" error

Installation was a series of 5 simple steps:
first, install homebrew itself from command in the home page:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
After that, following instructions in this page, and changing ~/.bash_profile to ~/.profile as I am using Ubuntu as my wsl distro, i had to give these commands:
test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
But now, when I try to run brew, I get command not found error.
In a wsl environment, brew is installed at location: /home/linuxbrew/.linuxbrew/ which is not part of the path.
So we simply need to add that to path, and it works. I am using zsh as my shell, so I add these lines to my ~/.zshrc file (in ubuntu file system) :
export BREW_HOME="/home/linuxbrew/.linuxbrew/bin"
export PATH="$PATH:$BREW_HOME"
if you happen to need to share your .zshrc across different OS, you can do some OS check in your zshrc file to see if it is macOS or linux/wsl:
case `uname` in
Linux)
## add brew home to PATH in linux/WSL
brew_home=/home/linuxbrew/.linuxbrew
if [ -d "${brew_home}" ]; then
export PATH=${brew_home}/bin:$PATH
fi
javac_loc=/usr/bin/javac
if [ -x "$javac_loc" ]; then
export JAVA_HOME=$(readlink -f $(dirname $(readlink -f $javac_loc)))
fi
;;
Darwin)
## Do macOS thing...
export JAVA_HOME=$(/usr/libexec/java_home)
;;
esac

Ruby version not update using rbenv on mac

I follow this tutorial
Install homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install Ruby
brew install rbenv ruby-build
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
rbenv install 2.4.0
rbenv global 2.4.0
ruby -v
but output ruby -v still
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
running on mac OS Sierra 10.12
One of the steps of the installation is this one:
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
Which writes a command into your .bash_profile.
You need to restart your Bash session (quit the Terminal and open a new one) to take it into effect.
I was having the same issues and mislav's comment here [https://github.com/rbenv/rbenv/issues/939][1] fixed it for me.
Add eval "$(rbenv init -)" line to your .bash_profile.
Works for me.

Find the install location of brew on OS X

I'm creating a BASH scrip which requires a couple of applications to be installed. ffmpeg and sox
To ensure they are in place when my script runs I first check for the installation of Homebrew with :
#!/bin/bash
which -s brew
if [[ $? != 0 ]] ; then
# Install Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
fi
Then I check that sox and ffmpeg are installed with :
echo "---- checking for sox ----"
which -s sox || /usr/local/bin/brew install sox
echo "---- checking for ffmpeg ----"
which -s ffmpeg || /usr/local/bin/brew install ffmpeg
The problem I am facing is when Homebrew is installed but in a non-standard location.
I have to use the full path to Homebrew because this script is being run within Playtypus.
So the question is : How can I reliably get the installed path of Homebrew in a BASH script?
Answering my own question...
You can test the output of which brew and deal with things accordingly. To gracefully deal with the case where Homebrew is not installed you can use if which brew 2> /dev/null which redirects stderr to /dev/null.
brew --prefix is also useful here as it give the path to where Homebrew installed applications are symlinked to, rather than their actual install path.
A script which works and shows this working :
#!/bin/bash
if which brew 2> /dev/null; then
brewLocation=`which brew`
appLocation=`brew --prefix`
echo "Homebrew is installed in $brewLocation"
echo "Homebrew apps are run from $appLocation"
else
echo "Can't find Homebrew"
echo "To install it open a Terminal window and type :"
echo /usr/bin/ruby -e \"\$\(curl\ \-fsSL\ https\:\/\/raw\.github\.com\/Homebrew\/homebrew\/go\/install\)\"
fi
Thanks to Allendar for the pointers.
Just to add to this, Homebrew's --prefix mode has been enhanced here in the far-flung future of 2020 (or maybe it was always this way), so that it now takes a package name as an argument. Meaning locating those "keg-only" packages which aren't linked into standard paths is as easy as:
$ brew --prefix ffmpeg
/usr/local/opt/ffmpeg

Resources