Use of Homebrew on Mac (Homebrew makes OS X more complete)

Keywords: brew OpenSSL github Ruby

What is 0 Homebrew?

"Homebrew installs the stuff you need that Apple did't. - Homebrew makes OS X more complete."

Homebrew's official website [1] (Multilingual Version) Briefly describes how to install and use the tool, and provides its own Wiki.


1 Install Homebrew

The installation of brew is simple, using a ruby command, and ruby is installed by default on the Mac system.

gerryyang@mba:bin$ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

Detailed instructions for installing brew can be found in the wiki instructions on its github [2]:

"
Installation

The suggested and easiest way to install Homebrew is on the homepage. We don't duplicate it here because it is asecurity risk to list it on a user-editable wiki.

The standard script installs Homebrew to /usr/local so that you don't need sudo when youbrew install. It is acareful script, it can be run even if you have stuff installed to/usr/local already. It tells you exactly what it will do before it does it too. And you have to confirm everything it will do before it starts.

There are other ways to install Homebrew which provide you with more flexibility. They are listed below the requirements.

"
  1. gerryyang@mba:~$ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"  
  2. It appears Homebrew is already installed. If your intent is to reinstall you  
  3. should do the following before running this installer again:  
  4.   
  5.     rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup  

Since brew has been installed on my system, executing the installation command again will prompt me that brew already exists.



2. Use of Homebrew

Look at brew's specific usage:

  1. gerryyang@mba:~$brew  
  2. Example usage:  
  3.   brew [info | home | options ] [FORMULA...]  
  4.   brew install FORMULA...  
  5.   brew uninstall FORMULA...  
  6.   brew search [foo]  
  7.   brew list [FORMULA...]  
  8.   brew update  
  9.   brew upgrade [FORMULA...]  
  10.   brew pin/unpin [FORMULA...]  
  11.   
  12. Troubleshooting:  
  13.   brew doctor  
  14.   brew install -vd FORMULA  
  15.   brew [--env | --config]  
  16.   
  17. Brewing:  
  18.   brew create [URL [--no-fetch]]  
  19.   brew edit [FORMULA...]  
  20.   open https://github.com/Homebrew/homebrew/wiki/Formula-Cookbook  
  21.   
  22. Further help:  
  23.   man brew  
  24.   brew home  
  25.   
  26. gerryyang@mba:~$  



3 Homebrew's Interesting Questions

Here are some common questions about Homebrew [3]:

(1) The software you want can not be found in OS X, so you can use brew to install it.

  1. gerryyang@mba:~$brew install wget  
  2. ==> Downloading http://ftpmirror.gnu.org/wget/wget-1.14.tar.gz  
  3. ######################################################################## 100.0%  
  4. ==> ./configure --prefix=/usr/local/Cellar/wget/1.14 --sysconfdir=/usr/local/etc  
  5. ==> make install  
  6. Warning: Could not link wget. Unlinking...  
  7. Error: The `brew link` step did not complete successfully  
  8. The formula built, but is not symlinked into /usr/local  
  9. You can try again using `brew link wget'  
  10.   
  11. Possible conflicting files are:  
  12. /usr/local/bin/wget  
  13. /usr/local/share/man/man1/wget.1  
  14. ==> Summary  
  15. <span style="font: 13.0px Monaco">/usr/local/Cellar/wget/1.14: 8 files, 688K, built in 2.3 minutes</span>   

Since wget was previously installed in source mode, the brew installation will prompt conflicting errors because / usr/locat/bin/wget already exists. In fact, Homebrew subpacks the package into a separate directory (/ usr/local/Cellar), and then symlink to / usr/local.  

(2) How to update the locally installed package?

Step 1: Update brew:

brew update

  1. gerryyang@mba:bin$brew update  
  2. Already up-to-date.  

Step 2: Update all package s:
brew upgarde

  1. gerryyang@mba:bin$brew upgrade  
  2. ==> Upgrading 1 outdated package, with result:  
  3. wget 1.15  
  4. ==> Upgrading wget  
  5. ==> Installing wget dependency: openssl  
  6. ==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/openssl-1.0  
  7. ######################################################################## 100.0%  
  8. ==> Pouring openssl-1.0.1f.mavericks.bottle.tar.gz  
  9. ==> Caveats  
  10. This formula is keg-only, so it was not symlinked into /usr/local.  
  11.   
  12. Mac OS X already provides this software and installing another version in  
  13. parallel can cause all kinds of trouble.  
  14.   
  15. The OpenSSL provided by OS X is too old for some software.  
  16.   
  17. Generally there are no consequences of this for you. If you build your  
  18. own software and it requires this formula, you'll need to add to your  
  19. build variables:  
  20.   
  21.     LDFLAGS:  -L/usr/local/opt/openssl/lib  
  22.     CPPFLAGS: -I/usr/local/opt/openssl/include  
  23.   
  24. ==> security find-certificate -a -p /Library/Keychains/System.keychain > '/usr/l  
  25. ==> security find-certificate -a -p /System/Library/Keychains/SystemRootCertific  
  26. ==> mv -f /usr/local/etc/openssl/osx_cert.pem.tmp /usr/local/etc/openssl/osx_cer  
  27. ==> Summary  
  28. /usr/local/Cellar/openssl/1.0.1f: 429 files, 15M  
  29. ==> Installing wget  
  30. ==> Downloading http://ftpmirror.gnu.org/wget/wget-1.15.tar.gz  
  31. ######################################################################## 100.0%  
  32. ==> ./configure --prefix=/usr/local/Cellar/wget/1.15 --sysconfdir=/usr/local/etc --with-ssl=openssl --with-libssl-prefix=/usr/local/opt/openssl --disable-iri  
  33. ==> make install  
  34. Warning: Could not link wget. Unlinking...  
  35. Error: The `brew link` step did not complete successfully  
  36. The formula built, but is not symlinked into /usr/local  
  37. You can try again using `brew link wget'  
  38.   
  39. Possible conflicting files are:  
  40. /usr/local/bin/wget  
  41. /usr/local/share/man/man1/wget.1  
  42. ==> Summary  
  43. /usr/local/Cellar/wget/1.15: 8 files, 700K, built in 73 seconds  
  44. gerryyang@mba:bin$  


(3) How to delete Homebrew?

If you installed to /usr/local then you can use the script in this gist to uninstall — it will only remove Homebrew and the stuff Homebrew installed leaving anything else in /usr/local alone.

Provided you haven't put anything else in Homebrew's prefix(brew --prefix), you can generally just rm -rf that directory. Thisis because Homebrew won't touch files outside its prefix.


(4) Where is the storage path of the package downloaded by Homebrew?

  1. gerryyang@mba:bin$brew --cache  
  2. /Library/Caches/Homebrew  
  3. gerryyang@mba:bin$ls /Library/Caches/Homebrew/  
  4. Formula/                                wget-1.14.tar.gz  
  5. coreutils-8.22.tar.xz                  wget-1.15.tar.gz  
  6. openssl-1.0.1f.mavericks.bottle.tar.gz  xz-5.0.5.mavericks.bottle.2.tar.gz  
  7. gerryyang@mba:bin$ls /Library/Caches/Homebrew/Formula/  
  8. coreutils.brewing  openssl.brewing  wget.brewing  xz.brewing  
  9.   
  10. gerryyang@mba:bin$  

(5) Can I install my stuff in / usr/local?

Yes, brew is designed to not get in your way so you can use it how youlike.

Install your own stuff, but be aware that if you install common libraries, like libexpat yourself, it may cause trouble when trying to build certain Homebrew formula. As a result brew doctor will warn you about this.

Thus it's probably better to install your own stuff to the Cellar and then brew link it. Like so:

$ cd foo-0.1
$ brew diy
./configure —prefix=/usr/local/Cellar/foo/0.1
$ ./configure —prefix=/usr/local/Cellar/foo/0.1
[snip]
$ make && make install
$ brew link foo
Linking /usr/local/Cellar/foo/0.1… 17 symlinks created

In my environment, the test is as follows:

  1. gerryyang@mba:bin$brew doctor  
  2. Warning: Unbrewed dylibs were found in /usr/local/lib.  
  3. If you didn't put them there on purpose they could cause problems when  
  4. building Homebrew formulae, and may need to be deleted.  
  5.   
  6. Unexpected dylibs:  
  7.     /usr/local/lib/libboost_atomic.dylib  
  8.     /usr/local/lib/libboost_chrono.dylib  
  9.     /usr/local/lib/libboost_context.dylib  
  10.     /usr/local/lib/libboost_date_time.dylib  
  11.     /usr/local/lib/libboost_filesystem.dylib  
  12.     /usr/local/lib/libboost_graph.dylib  
  13.     /usr/local/lib/libboost_iostreams.dylib  
  14.     /usr/local/lib/libboost_locale.dylib  
  15.     /usr/local/lib/libboost_log.dylib  
  16.     /usr/local/lib/libboost_math_c99.dylib  
  17.     /usr/local/lib/libboost_math_c99f.dylib  
  18.     /usr/local/lib/libboost_math_c99l.dylib  
  19.     /usr/local/lib/libboost_math_tr1.dylib  
  20.     /usr/local/lib/libboost_math_tr1f.dylib  
  21.     /usr/local/lib/libboost_math_tr1l.dylib  
  22.     /usr/local/lib/libboost_prg_exec_monitor.dylib  
  23.     /usr/local/lib/libboost_program_options.dylib  
  24.     /usr/local/lib/libboost_python.dylib  
  25.     /usr/local/lib/libboost_random.dylib  
  26.     /usr/local/lib/libboost_regex.dylib  
  27.     /usr/local/lib/libboost_serialization.dylib  
  28.     /usr/local/lib/libboost_signals.dylib  
  29.     /usr/local/lib/libboost_system.dylib  
  30.     /usr/local/lib/libboost_thread.dylib  
  31.     /usr/local/lib/libboost_timer.dylib  
  32.     /usr/local/lib/libboost_unit_test_framework.dylib  
  33.     /usr/local/lib/libboost_wave.dylib  
  34.     /usr/local/lib/libboost_wserialization.dylib  
  35.   
  36. Warning: Unbrewed static libraries were found in /usr/local/lib.  
  37. If you didn't put them there on purpose they could cause problems when  
  38. building Homebrew formulae, and may need to be deleted.  
  39.   
  40. Unexpected static libraries:  
  41.     /usr/local/lib/libboost_atomic.a  
  42.     /usr/local/lib/libboost_chrono.a  
  43.     /usr/local/lib/libboost_context.a  
  44.     /usr/local/lib/libboost_coroutine.a  
  45.     /usr/local/lib/libboost_date_time.a  
  46.     /usr/local/lib/libboost_exception.a  
  47.     /usr/local/lib/libboost_filesystem.a  
  48.     /usr/local/lib/libboost_graph.a  
  49.     /usr/local/lib/libboost_iostreams.a  
  50.     /usr/local/lib/libboost_locale.a  
  51.     /usr/local/lib/libboost_log.a  
  52.     /usr/local/lib/libboost_math_c99.a  
  53.     /usr/local/lib/libboost_math_c99f.a  
  54.     /usr/local/lib/libboost_math_c99l.a  
  55.     /usr/local/lib/libboost_math_tr1.a  
  56.     /usr/local/lib/libboost_math_tr1f.a  
  57.     /usr/local/lib/libboost_math_tr1l.a  
  58.     /usr/local/lib/libboost_prg_exec_monitor.a  
  59.     /usr/local/lib/libboost_program_options.a  
  60.     /usr/local/lib/libboost_python.a  
  61.     /usr/local/lib/libboost_random.a  
  62.     /usr/local/lib/libboost_regex.a  
  63.     /usr/local/lib/libboost_serialization.a  
  64.     /usr/local/lib/libboost_signals.a  
  65.     /usr/local/lib/libboost_system.a  
  66.     /usr/local/lib/libboost_test_exec_monitor.a  
  67.     /usr/local/lib/libboost_thread.a  
  68.     /usr/local/lib/libboost_timer.a  
  69.     /usr/local/lib/libboost_unit_test_framework.a  
  70.     /usr/local/lib/libboost_wave.a  
  71.     /usr/local/lib/libboost_wserialization.a  
  72.   
  73. Warning: You have unlinked kegs in your Cellar  
  74. Leaving kegs unlinked can lead to build-trouble and cause brews that depend on  
  75. those kegs to fail to run properly once built. Run `brew link` on these:  
  76.   
  77.     wget  
  78. gerryyang@mba:bin$  

(6) Why did you choose the name Homebrew?
mxcl was too concerned with the beer theme and didn't consider that the project may actually prove popular. By the time he realized it was too late. However, today, the first google hit for "homebrew" is not beer related ;-)

It seems that the author is an alcoholic!

(7) For more QA, refer to Homebrew's Wiki [4]


(8) Recommendations for some common installations

  1. gerryyang@mba:bin$brew list  
  2. coreutils  openssl  wget  xz  

Introduction to Coreutils 

The GNU Core Utilities are the basic file, shell and text manipulation utilities of the GNU operating system.
These are the core utilities which are expected to exist on every operating system.

http://www.gnu.org/software/coreutils/


4 reference

[1] http://brew.sh/index_zh-cn.html

[2] https://github.com/Homebrew/homebrew/wiki/Installation

[3] https://github.com/Homebrew/homebrew/wiki/FAQ

[4] https://github.com/Homebrew/homebrew/wiki

Posted by daq on Fri, 04 Jan 2019 17:24:11 -0800