- Richard Feynman -
Homebrew and Macports
Contents
- 1 Install required packages
- 1.1 XCode Installation
- 1.2 Install extra package manager
- 1.2.1 Quick guide to using Homebrew and MacPorts
- 1.2.2 Homebrew
- 1.2.3 MacPorts
- 2 Using both Homebrew and MacPorts
- 3 Links
MacOS is missing a couple of programs we're using in our courses/books. You can get around this by installing either Homebrew or The MacPorts Project. Both of them require that xcode is installed. Once you have these installed you can use our download script (see Software used) to prepare your computer for using our material. Some course may require you to install additional software.
Install required packages
XCode Installation
Install xcode
Note: after installation you need to accept the license terms. Read them and execute the following command in a terminal window sudo xcodebuild -license
Install extra package manager
Apple ships MacOS with a couple of useful programs, such as bash. The problem for us is that the programs shipped are far from enough and that some of them are old to say the least. As an example the bash version installed in MacOs is from 2007, so it's kind of old. You can download additional software using the apple store (or what ever it's called today) but the packages here are not enough and it will soon become cumbersome to install all the packages we need without someone making sure the versions work together. So we need an additional package manager taking care of our packages. We know of two ones:
You will find installation hints and some useful tricks per package manager below.
Quick guide to using Homebrew and MacPorts
Homebrew
- Installs in directory:
/usr/local
- Searching for a package (e g wget):
brew search wget
- Install a package (e g wget):
brew install wget
MacPorts
- Installs in directory:
/opt/local/
- Searching for a package (e g wget):
port search wget
- Install a package (e g wget):
sudo port install wget
Homebrew
Installation
Follow the instructions on this page: Homebrew (installation)
Here are some samples from our bash session when we installed Homebrew on our mac.
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following existing directories will be made group writable:
/usr/local/bin
/usr/local/lib
==> The following existing directories will have their owner set to juneday:
/usr/local/bin
/usr/local/lib
==> The following existing directories will have their group set to admin:
/usr/local/bin
/usr/local/lib
==> The following new directories will be created:
/usr/local/Cellar
/usr/local/Homebrew
/usr/local/Frameworks
/usr/local/etc
/usr/local/include
.....
Tapped 4479 formulae (4,759 files, 12MB)
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/juneday/Library/Caches/Homebrew...
==> Deleting /Library/Caches/Homebrew...
Already up-to-date.
==> Installation successful!
==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics.html
==> Next steps:
- Run `brew help` to get started
- Further documentation:
https://docs.brew.sh
Install packages
Since some time during 2019, they changed homebrew so that it doesn't come with Bash installed. So the first thing you should do after installing homebrew is to install Bash:
$ brew install bash
Let's say you want to install the program wget
. All you need to do now is to type the following in a terminal:
$ brew install wget
and after this simple procedure you can use wget
, e g like this:
$ brew install wget
==> Installing dependencies for wget: gettext, libunistring, libidn2, openssl@1.1
==> Installing wget dependency: gettext
==> Downloading https://homebrew.bintray.com/bottles/gettext-0.19.8.1.sierra.bot
==> Downloading from https://akamai.bintray.com/83/8368522242c5fe33acd5c80b5f132
######################################################################## 100.0%
==> Pouring gettext-0.19.8.1.sierra.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.
If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile
For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/gettext/lib
CPPFLAGS: -I/usr/local/opt/gettext/include
==> Summary
🍺 /usr/local/Cellar/gettext/0.19.8.1: 1,934 files, 16.9MB
==> Installing wget dependency: libunistring
==> Downloading https://homebrew.bintray.com/bottles/libunistring-0.9.8.sierra.b
==> Downloading from https://akamai.bintray.com/b6/b685813e92dbd3a4eedcaac4b1a87
######################################################################## 100.0%
==> Pouring libunistring-0.9.8.sierra.bottle.tar.gz
🍺 /usr/local/Cellar/libunistring/0.9.8: 53 files, 4.4MB
==> Installing wget dependency: libidn2
==> Downloading https://homebrew.bintray.com/bottles/libidn2-2.0.4.sierra.bottle
######################################################################## 100.0%
==> Pouring libidn2-2.0.4.sierra.bottle.tar.gz
🍺 /usr/local/Cellar/libidn2/2.0.4: 46 files, 580.8KB
==> Installing wget dependency: openssl@1.1
==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.0g_1.sierra
==> Downloading from https://akamai.bintray.com/b0/b0d78618e300fd5fceb5bf98001d4
######################################################################## 100.0%
==> Pouring openssl@1.1-1.1.0g_1.sierra.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs
and run
/usr/local/opt/openssl@1.1/bin/c_rehash
This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile
For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/openssl@1.1/lib
CPPFLAGS: -I/usr/local/opt/openssl@1.1/include
==> Summary
🍺 /usr/local/Cellar/openssl@1.1/1.1.0g_1: 6,585 files, 15.6MB
==> Installing wget
==> Downloading https://homebrew.bintray.com/bottles/wget-1.19.2_1.sierra.bottle
==> Downloading from https://akamai.bintray.com/38/381e209d4c0af56747f2a4ae4671d
######################################################################## 100.0%
==> Pouring wget-1.19.2_1.sierra.bottle.tar.gz
🍺 /usr/local/Cellar/wget/1.19.2_1: 50 files, 3.8MB
$
Search for packages
A program we know the name of
Let's say we want to install the program tree
. We can use the search function in Homebrew:
$ brew search tree
==> Searching local taps...
mvptree pstree tree treecc treefrog
==> Searching taps on GitHub...
==> Searching blacklisted, migrated and deleted formulae...
We can see that there are a couple of different programs matching tree. It's hard for us give general rule of which program to chose but we suggest you read a bit more about each program using brew search
:
$ brew info tree
tree: stable 1.7.0 (bottled)
Display directories as trees (with optional color/HTML output)
http://mama.indstate.edu/users/ice/tree/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/tree.rb
This seems like a good choice so let's install it using brew install
:
$ brew install tree
==> Downloading https://homebrew.bintray.com/bottles/tree-1.7.0.sierra.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring tree-1.7.0.sierra.bottle.1.tar.gz
🍺 /usr/local/Cellar/tree/1.7.0: 7 files, 113.3KB
A program we know parts of the name of
Let's say we want to search for a program which we only remember parts of the name of, let's say ls
$ brew search ls
==> Searching local taps...
aardvark_shell_utils ebook-tools libxlsxwriter psutils
adr-tools ec2-ami-tools libxmlsec1 pulseaudio
appscale-tools ec2-api-tools lsdvd pwntools
avro-tools eiffelstudio lsh rails-completion
aws-cfn-tools elb-tools lsof rds-command-line-tools
b2-tools eot-utils lsyncd recutils
bamtools euca2ools ltc-tools renameutils
bcftools findutils lwtools rom-tools
bedtools flow-tools mailutils samtools
bibutils fonttools mbedtls scummvm-tools
binutils fsevents-tools mdbtools shellshare
bpm-tools garmintools megatools skktools
bzr-externals genometools mjpegtools smartmontools
bzrtools gerrit-tools moreutils somagic-tools
cctools git-utils moz-git-tools spatialite-tools
cctools-headers glslang msitools speech-tools
cdrtools glslviewer mtools sslscan
charm-tools gnome-doc-utils mupdf-tools sslsplit
coreutils gnutls muttils sundials
cpmtools gperftools mvtools swftools
crush-tools gputils nfcutils t1utils
cuetools grails num-utils tlsdate
cvsutils grails@2.5 objc-codegenutils u-boot-tools
daemontools gupnp-tools ocamlsdl uniutils
dateutils hfsutils ogmtools vcftools
debianutils hopenpgp-tools olsrd vorbis-tools
desktop-file-utils html-xml-utils opus-tools wireguard-tools
diffutils icon-naming-utils orc-tools xlslib
dmtx-utils icoutils osslsigncode xml-coreutils
docker-ls idutils osxutils xmlsectool
docker-machine-parallels inetutils parquet-tools xmlsh
docutils irrtoolset patchutils xmlstarlet
dosfstools jdnssec-tools pdf-redact-tools yelp-tools
dvd+rw-tools lcdf-typetools picard-tools zsh-navigation-tools
dvdrtools librealsense plotutils
dwarfutils librealsense@1 proctools
e2tools librtlsdr psftools
==> Searching taps on GitHub...
==> Searching blacklisted, migrated and deleted formulae...
This gives us a bit too many programs, but you'll get the point.
Using the bash from Homebrew
Homebrew ships a new and fresh bash. You can us this in (at least) two ways:
- manually - by starting bash manually (in bash)
- automatically - using a settings file
Read more about bash versions at Bash_version.
Using the bash from Homebrew - manually
When you start a terminal in MacOS bash is started along with the terminal. The version of bash is the old one. If you want t fresher bash you can simply type
$ bash
Using the bash from Homebrew - automatically
Homebrew installs bash in /usr/local/bin/
and adds this directory to your PATH. You can check that the path is set by 1) print the PATH variable and 2) see what bash will be started:
$ echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$ which bash
/usr/local/bin/bash
If you want, which we assume since you're reading this, to make the Homebrew version of bash the default you need to do execute a few commands, see below. This means that this version of bash will be started when you start a new terminal window.
1 $ sudo -s
2 bash-3.2# which bash >> /etc/shells
3 bash-3.2# exit
4 $ chsh -s $(which bash)
5 Changing shell for juneday.
6 Password for juneday:
7 $
Explaining what's going on above:
-
sudo -s
- start a new shell as superuser (root) -
which bash >> /etc/shells
- add the Homebrew version of bash to a list of acceptable shells -
exit
- leave the bash running as superuser -
chsh -s $(which bash)
- Change the default shell using chsh (tryman chsh
- printout from chsh
- chsh asking for your password - type it in
- normal prompt
The next terminal you start should be running the Homebrew version of bash.
MacPorts
Installation
The MacPorts Project (installation).
- Note: make sure that the command
port
can be found using the PATH variable. Try typingport version
. If you see something likeVersion: 2.3.5
you're fine. If not add read this page MacPorts and the Shell
When using port you might see a warning like this:
Warning: xcodebuild exists but failed to execute
Warning: Xcode does not appear to be installed; most ports will likely fail to build.
Fix this by executing the following command:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Read more about problems using MacPorts here: ProblemHotlist
Install packages
Search for packages
A program we know the name of
Let's again say we want to install the program tree
. We can use the search function in MacPorts:
$ port search tree
bact @0.13 (math)
a Boosting Algorithm for Classification of Trees
castxml @20171013 (lang)
CastXML is a C-family abstract syntax tree XML output tool.
cvsgraph @1.7.0_2 (devel)
utility for graphical representation of CVS/RCS revision tree
etree-scripts @1.4 (audio)
utilities useful to people who use the etree network
ftpsync @1.3.04_5 (net)
Synchronizes a local and a remote ftp directory tree
...
tree @1.7.0 (sysutils)
display tree-view of directories with optional color/HTML output
tree-puzzle @5.2 (science)
a computer program to reconstruct phylogenetic trees from molecular sequence data by maximum likelihood
treecc @0.3.10_1 (devel)
Manages generation of code to handle syntax trees.
treehh @2.65_1 (science)
Data Analysis and Scientific Plotting
treeline @1.4.1 (office, pim, python)
Advanced outliner and personal information manager
X-MasTree @1.4 (aqua, amusements)
Christmas tree
xom @1.2.10 (java, devel, textproc)
A tree-based API for XML processing
Found 148 ports.
We got so many hits we had to snip the printout. We can see that there is a tool cooled tree
which most likely is the program we want. Let's install it:
$ port install tree
Error: Insufficient privileges to write to MacPorts install prefix.
Ah, ok. We need to be superuser when using MacPorts. Let's execute the installation command as superuser.
$ sudo port install tree
Password:
Warning: xcodebuild exists but failed to execute
Warning: Xcode does not appear to be installed; most ports will likely fail to build.
---> Fetching archive for tree
---> Attempting to fetch tree-1.7.0_0.darwin_16.x86_64.tbz2 from https://packages.macports.org/tree
---> Attempting to fetch tree-1.7.0_0.darwin_16.x86_64.tbz2.rmd160 from https://packages.macports.org/tree
---> Installing tree @1.7.0_0
---> Activating tree @1.7.0_0
---> Cleaning tree
---> Updating database of binaries
---> Scanning binaries for linking errors
---> No broken files found.
Do you see the warning? Let's fix it:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
A program we know parts of the name of
Let's again say we want to search for a program which we only remember parts of the name of, let's say ls
$ port search ls
2Pong @1.0.1a (games)
Pong game with 2 balls, 2 and 4 player support
alliance @5.0-20110203_2 (science)
Alliance, CAD and libraries for VLSI design
am-utils @6.1.5_1 (sysutils)
The Berkeley Automounter Suite of Utilities
amttools @1.4_2 (sysutils)
Intel AMT® Serial-over-LAN client and tools
angelscript @2.31.2 (devel)
Flexible cross-platform scripting library
aolserver @4.5.1 (www)
America Online's open-source web server
ap-utils @1.3.3 (net)
Utilities for AMTEL, NWN, ME102 wireless access points
....
xz @5.2.3 (archivers)
XZ Utils
yelp-tools @3.18.0 (gnome)
Tools to help create Yelp documentation.
yorick-yutils @1.5.2 (science, yorick)
Various utilities for the Yorick language
yum-utils @1.1.17_1 (sysutils)
Utilities based around the yum package manager
Found 1281 ports.
$
This gives us a bit too many programs, but you'll get the point just as you did when reading about Homebrew.
Using the bash from MacPorts
MacPorts ships a new and fresh bash. You can us this in (at least) two ways:
- manually - by starting bash manually (in bash)
- automatically - using a settings file
Read more about bash versions at Bash_version.
Using the bash from MacPorts - manually
When you start a terminal in MacOS bash is started along with the terminal. The version of bash is the old one. If you want t fresher bash you can simply type
$ bash
Using the bash from MacPorts - automatically
MacPorts installs bash in /usr/local/bin/
and adds this directory to your PATH. You can check that the path is set by 1) print the PATH variable and 2) see what bash will be started:
$ echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$ which bash
/opt/local/bin/bash
$
If you want, which we assume since you're reading this, to make the Homebrew version of bash the default you need to do execute a few commands, see below. This means that this version of bash will be started when you start a new terminal window.
1 $ sudo -s
2 bash-3.2# which bash >> /etc/shells
3 bash-3.2# exit
4 $ chsh -s $(which bash)
5 Changing shell for juneday.
6 Password for juneday:
7 $
Explaining what's going on above:
-
sudo -s
- start a new shell as superuser (root) -
which bash >> /etc/shells
- add the Homebrew version of bash to a list of acceptable shells -
exit
- leave the bash running as superuser -
chsh -s $(which bash)
- Change the default shell using chsh (tryman chsh
- printout from chsh
- chsh asking for your password - type it in
- normal prompt
The next terminal you start should be running the MacPorts version of bash.
Using both Homebrew and MacPorts
While this is not something we se very useful, but if you're brave and beautiful you might do this in order to test which is best (Homebrew or MacPorts) or simply because it is possible. The latter is btw a great reason.
When having bot Homebrew and MacPorts installed you will end up with (at least) three versions of bash:
- Homebrew's version
- MacPorts's version
- Apple's version (again, this version is from year 2007!!)
You know by now (otherwise check out the following section in our FAQ: xxx: command not found) that you need to set the PATH to point our your favorite package manager's path as the first path in your PATH. Here are examples of how to adjust your PATH variable. Depending on the package manager you should add the following to your ~/.bashrc
file:
- Homebrew:
export PATH=/usr/local/bin:$PATH
- MacPorts:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
- Apple:
export PATH=/bin:/usr/bin:/usr/sbin:$PATH
Links
Package managers for MacOS: