All notes
Homebrew

Quick start

It is a package manager for macOS. brew website.


/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"


# https://github.com/caskroom/homebrew-cask/issues/5328
# If there is 404 error for downloading packages, it may be caused by an old version of Homebrew Cask.
brew update && brew cleanup && brew cask cleanup


# To see all files in a package:
brew ls $package
brew info $package
# To find the package for a file, look at the file like this:
ls -l /usr/local/bin/whatever

# Where does stuff get downloaded?
brew --cache
# /Users/me/Library/Caches/Homebrew

brew search $AppName

########## Update related

# Update the formulae and Homebrew itself
brew update

# Find out what is outdated
brew outdated

# Upgrade everything with:
brew upgrade
# Upgrade a specific formula with:
brew upgrade $FORMULA

# Stop something from being updated/upgraded:
brew pin $FORMULA
# Allow that formulae to update again:
brew unpin $FORMULA

########## Clean up old versions

# Dry-run
brew cleanup -n
# Really run
brew cleanup

########## Troubleshooting

brew update #
brew update # (twice)
brew doctor

########## Other

# Quickly remove something from /usr/local
brew unlink $FORMULA
# Readd
brew link $FORMULA

# Activate a previously installed version of a formula
brew info $FORMULA
brew switch $FORMULA $VERSION

# Install into Homebrew without formulae
./configure --prefix=/usr/local/Cellar/foo/1.2 && make && make install && brew link foo

Commands

info

To show the installation path of a package:


brew info PKGNAME

services

mysql, mariadb



#---------- mysql

# wcfNote: if "mysql.server start" fails, check /usr/local/var/mysql/*.err for error info, mostly it may because of config error in /usr/local/etc/my.cnf.

# We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation

# MySQL is configured to only allow connections from localhost by default
# To connect run:
mysql -uroot

# To have launchd start mysql now and restart at login:
brew services start mysql
# Or, if you don't want/need a background service you can just run:
mysql.server start

#---------- [email protected]

# https://gist.github.com/operatino/392614486ce4421063b9dece4dfe6c21

brew info [email protected]
brew install [email protected]

brew tap homebrew/services
brew services start [email protected]
# Equal to :
# ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
# launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

brew services list

# Force link 5.7 version
brew link [email protected] --force
# Verify the installed MySQL instance:
mysql -V

mysqladmin -u root password 'yourpassword'

#---------- mariadb

brew info mariadb

# To have launchd start mariadb now and restart at login:
brew services start mariadb

brew services list
brew services restart shadowsocks-libev
# /usr/local/opt/shadowsocks-libev/bin/ss-local -c /usr/local/etc/shadowsocks-libev.json -u
# REMEMER: shadowsocks is not http proxy but socks5 proxy.

# Integrates Homebrew formulae with macOS' launchctl manager.
# If sudo is passed, operate on /Library/LaunchDaemons (started at boot).
# Otherwise, operate on ~/Library/LaunchAgents (started at login).

tap



# Will add https://github.com/ruffjs/homebrew-ruff to brew repo.
brew tap ruffjs/ruff
brew install ruff

# You can also install via URL:
brew install https://raw.githubusercontent.com/ruffjs/homebrew-ruff/master/<formula>.rb

cask



brew cask install vagrant
brew cask install chefdk # Downloading https://packages.chef.io/stable/mac_os_x/10.12/chefdk-2.0.28-1.dmg

#---------- Install mysql workbench
brew search mysql
brew cask install mysqlworkbench

FAQ

Another version is already linked

Another version is already linked: /usr/local/Cellar/libyaml/0.1.4

Try brew upgrade libyaml; brew link libyaml. See github.com: homebrew.

/usr/local permissions

jamf.com mentioned about how homebrew setting /usr/local permissions affect other apps. Solution:


sudo chown -R $(whoami):admin /usr/local
# This will fix it
sudo chown -R root:wheel /usr/local/jamf

And it seems not possible for homebrew to change its installation destination, see SuperUser: change install location and prefix. Simply put, the /usr/local/ is the default prefix for most packages.

Solution

wcfNote: one solution is to add me - the user - to wheel group, so that "me" and write in /usr/local/bin:


# https://superuser.com/questions/60150/is-there-a-usermod-equivalent-in-terminal-for-os-x-10-6-1
sudo dscl . append /Groups/wheel GroupMembership me
If there is any problem, e.g. pcre-config says no permission:

chown `whoami` pcre-config

Install python-pip

SO: install pip on MacOS.


# Just install the pip.
sudo easy_install pip