MacPorts behind a proxy

How to get MacPorts working if you’re behind a proxy/firewall.

If you’re trying to use MacPorts, and you’re behind a proxy or firewall, chances are you’ll see errors like the following when you try to install or upgrade a port:

--->  Fetching some-package
--->  Attempting to fetch some-package.tar.bz2 from
Error: Target org.macports.fetch returned: fetch failed
Log for some-package is at: /opt/local/var/macports/logs/_some-package/main.log
Error: Unable to upgrade port: 1
To report a bug, see <>

In the not-so-distant past, it was rather complicated to get this working, using rsync etc.  Now, there’s just one file to edit:

sudo vim /opt/local/etc/macports/macports.conf

At the very bottom of the file, you’ll want to edit the following directives to reflect your proxy settings:


Just the http and skip settings may be enough for most, depending on how you get your source packages.  I keep forgetting about this fix, and it has cost me hours of manual package downloading while away from the proxied network, as I’d forgot about fixing the proxy settings … I hope it saves someone else some trouble!

Update: there’s yet another piece to this for those behind a firewall or proxy that blocks rsync protocol connections (on port 873): you’ll need to sync the MacPorts tree via Subversion, and then change your ports source to use the SVN tree.  The details can be found here, but for the impatient, the steps are essentially:

sudo mkdir -p /opt/local/var/macports/sources/
cd /opt/local/var/macports/sources/
sudo svn co .
sudo vim /opt/local/etc/macports/sources.conf
  • You’ll need to comment out (add a ‘#’ at the beginning of) the ‘rsync …’ line here, and then add  the following line to the end of this file:
    file:///opt/local/var/macports/sources/ [default]
sudo port -d sync
sudo portindex

Don’t forget to undo the above step for editing the sources file if you want to go back to updating MacPorts “normally” at some point.

Another update: If the Subversion method above fails, here’s another method to try that will likely work: instead of configuring MacPorts to connect via SVN, instruct it to download a tarball copy of the latest index with this line in sources.conf: [default]

As before, ensure this is the only `[default]` entry, or comment out the rest of the entries in the file.

You can then update your ports tree with:

cd /opt/local/etc/macports/ && sudo port -d sync && sudo portindex

If you don’t want to see the detail of the sync process, omit the `-d` flag.


10 thoughts on “MacPorts behind a proxy

  1. Pingback: LLyuan's Weblog

  2. You should change this line:



    file:///opt/local/var/macports/sources/ [default]

    • Good point; thanks Chris. I didn’t want to confuse things by having multiple `default`s, but in this case we’re commenting out the default. This also gives me a prod to add the tarball method that may help if the SVN method fails.

  3. Pingback: Make Macports work behind proxy | samkhan13

  4. Hello, i read your blog occasionally and i own a similar one and i was
    just wondering if you get a lot of spam comments?
    If so how do you reduce it, any plugin or anything you can suggest?
    I get so much lately it’s driving me mad so any help is very much appreciated.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s