Tips on MacPorts

DONG Yuxuan @ Feb 03, 2020 CST

MacPorts is the package manager I’m using in macOS. Personally I prefer it than Homebrew. But it also has some flaws so I give some tips about them for MacPorts beginners.

Installation and Updating in China

If you’re in China and install MacPorts by the .pkg file, you may stuck on “Running Package Scripts”. If it happens, it’s because of that your network is hard to connect the server of MacPorts to update. Nevermind, MacPorts is already installed, just not updated.1 Forcely kill the installer using the kill command.

Edit the following files to change sources MacPorts use to mirrors in China.

You can run sudo port selfupdate to update and finish the installation now.


Install Vim by sudo port install vim +huge. The +huge variant provides many important features like supporting the system clipboard.

Python Packages

After you have installed Python and pip with MacPorts. You may want to install Python packages that have executable files, Eg. virtualenv.

You can successfully install it. But when you type virtualenv from the shell, it can’t be found, because it’s not placed into $PATH.

That’s because MacPorts provides some Python packages by itself. For example, you can install virtualenv for Python 3.6 by running sudo port install py36-virtualenv. If MacPorts links executables from pip, it may conflict with executables from MacPorts.

Personally, I don’t think it’s a good decision.

Firstly, I think Python packages should be provided only by pip, not by a system package manager like MacPorts.

Secondly, if it really wants to do this, it should also do this on Ruby packages, Node.js packages, etc. But it doesn’t. If you install Ruby packages by gem, executables will be linked.

My solution is simple. Supposing MacPorts is installed in the default location /opt/local and we use Python 3.6, we link /opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/ to /usr/local/py3-bin and put it into my $PATH. If I want to switch the version of Python, I could just relink it.

Ruby Packages

After you install Ruby with MacPorts. You try to install Ruby packages with gem. For example, you run sudo gem install jekyll. But the building may fail for it can’t find some basic header files like stdio.h.

You should carefully check the output, it looks like the following:

sysroot /Applications/ doesn't exist

Run cd /Applications/ and check files. If MacOSX10.14.sdk or what the file you miss in your system really does not exist, you could make a symlink to MacOSX.sdk by yourself.

# under /Applications/

$ ln -s MacOSX.sdk MacOSX10.14.sdk