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 http://some.url.com/ 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 <http://guide.macports.org/#project.tickets>
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:
proxy_http proxy_https proxy_ftp proxy_rsync proxy_skip
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/svn.macports.org/trunk/dports/ cd /opt/local/var/macports/sources/svn.macports.org/trunk/dports/ sudo svn co http://svn.macports.org/repository/macports/trunk/dports/ . 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:
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:
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.