Migrate from MacPorts to Homebrew

I decided to migrate from MacPorts to Homebrew. 

home brew
Photo by Michael Surazhsky on Unsplash

The reasons are:

  • It is very intimidating when all of my coworkers use brew.
  • Most of the Google SDK documentation prefer homebrew to Macports.
  • I hope I can get another point of view when using a different package manager in OSX.
I will not talk much about technical reasons, since both Macports or Brew developers have a strong reason why they design those package managers that way. Some people rant about Ruby vs TCL, or silly things like how much packages each of them provides, etc. That's not the focus of this article. If that's your thing, go get a room for the endless debate. There was nothing religious about the decision.

I also didn't try to install both of them side by side since most STO users do not recommend it.

Okay. Let's start!

Uninstall All Ports

sudo port -fp uninstall installed

This way, you uninstall all the ports you have installed before. If you are not sure, make some backup for your configuration files (which I didn't do). 

Remove Users and Groups

You also need to remove the macports user and group, since it relates to the privilege separation. 

sudo dscl . -delete /Users/macports
sudo dscl . -delete /Groups/macports

If you specified a different name than macports, just replace the command above with your user or group name. This command helps you to find all users and groups in OSX.

dscl . list /groups | grep port
dscl . list /users | grep port


Clean up the rest

Macport puts every installation on /opt/local folder. So we need to purge everything inside that folder.

$ sudo rm -rf
\ /opt/local
\ /Applications/DarwinPorts
\ /Applications/MacPorts
\ /Library/LaunchDaemons/org.macports.*
\ /Library/Receipts/DarwinPorts*.pkg
\ /Library/Receipts/MacPorts*.pkg
\ /Library/StartupItems/DarwinPortsStartup
\ /Library/Tcl/darwinports1.0
\ /Library/Tcl/macports1.0
\ ~/.macports

It is absolutely fine if you don't have all the above paths, because that depends on which version of Macports you run.

I was stuck when deleting /opt/local/var/db/postgresql folder. The error message was "Operation not permitted". That is because we need to give full disk access to Terminal to do the task. Go to the "Security & Privacy" section, Privacy, Full Disk Access, and then check Terminal.

full disk access to terminal osx

Install Brew

Simply put this one line command into your Terminal.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

What that line does is just download the install.sh file and run it. You might consider that Brew uses /usr/local folder (instead of a custom /opt/local folder like Macports does), so be aware if you have existing executable files that may cause some conflicts.

My Experience of Brew (so far)

Brew works like a charm. I don't have difficulties installing some packages for web development.

brew doctor

This command will give you some warnings related to the OSX version, Command Line Tools release, or Xcode that outdated. You can ignore those warning messages and keep moving on.

  • Everything is owned by the user. No need to worry about risky root access while installing packages.
  • Every installed package is cleanly sandboxed.
  • Very up to date.
That's pretty much of it.

Comments

Popular Posts