Make Macports work behind proxy

I ended up struggling for months to get Macports to work and tried every installation method in but nothing worked. After drudging through numerous forums I finally discovered that sudo command “sanitizes” the shell environment and gets rid of the environment variables concerning proxy settings because of which commands like

sudo port -d selfupdate

don’t work. Also, many proxy servers aren’t configured to handle rsync.

So this blog is about one method that finally worked for me. Before I get into the method I assume that you know your proxy settings that may include a username and password for authentication and you have configured you browser to use them.

Getting Macports to work over http

Step 1: Get the installer from Macports download site

Download the latest installation package  for your particular OS from:

Follow through the prompts after opening it and install Macports but then trying to selfupdate might give this error:

DEBUG: MacPorts sources location: /opt/local/var/macports/sources/
—> Updating MacPorts base sources using rsync
rsync: failed to connect to Operation timed out (60)
rsync error: error in socket IO (code 10) at /SourceCache/rsync/rsync-42/rsync/clientserver.c(105) [receiver=2.6.9]
Command failed: /usr/bin/rsync -rtzv –delete-after rsync:// /opt/local/var/macports/sources/
Exit code: 10
DEBUG: Error synchronizing MacPorts sources: command execution failed
while executing
“macports::selfupdate [array get global_options] base_updated”
Error: /opt/local/bin/port: port selfupdate failed: Error synchronizing MacPorts sources: command execution failed

This is because the shell environment doesn’t have the variables specifying your systems proxy settings.

Use the following code to edit sources.conf using the vi editor in bash

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

Once the file is opened in the vi editor press the ‘a’ key on your keyboard to enter into –insert– mode. Scroll down to the bottom of file and comment out the following line by typing # in front of it.

rsync:// [default]

Bellow that line insert this line which will tell Macports to go fetch the daily tarball over http [default]

Next, press the ‘esc’ key on your keyboard to exit –insert– mode. Then type :x and press ‘return’ to save your changes and return to Terminal.

Step 2: Keep your proxy related environment variables

Similar to editing the sources.conf by using the vi editor in bash, edit the sudoer file:

sudo visudo

scroll to the bottom, enter into –insert– mode and append the following to the list of default specifications

Defaults        env_keep += "http_proxy HTTP_PROXY ftp_Proxy FTP_PROXY rsync_proxy RSYNC_PROXY"

Next, escape out of the –insert– mode and save your changes.

Now, type the following at the terminal to export environment variables. Replace “username”, “password”, “proxyURL” and “portNumber” with their values specifying your proxy settings:

export http_proxy=http://username:password@proxyURL:portNumber
export HTTP_PROXY=http://username:password@proxyURL:portNumberexport 
export ftp_proxy=ftp://username:password@proxyURL:portNumber
export FTP_PROXY=ftp://username:password@proxyURL:portNumber

rsync will most probably never work but just in case, add these variable as well… notice  that you don’t need rsync:// at the beginning of the value

export rsync_proxy=username:password@proxyURL:portNumber
export RSYNC_PROXY=username:password@proxyURL:portNumber

Use the bellow command to check the environment variables being used in the current session of the bash shell


Remember to check for these environment variables every time you run your Terminal and are about to use things like port, curl, homebrew, etc. that make use of your internet connection.

In case you want to erase those environment variables you can use:

unset http_proxy HTTP_PROXY

Step 3: Sync the port tree over http

Use the bellow command, not “sudo port selfupdate”

sudo port -d sync

Note: The -d in commands like “sudo port -d sync” is for activating the debug mode. Such options are mentioned in the man pages of the commands.

Step 4: Move onto other problems in life



  1. John DeStefano’s blog (also has method to use svn to update port tree):
  2. Alex’s blog:
  3. Joe Di Pole’s blog:
  4. Some macports ticket:
  5. Some really sad macports ticket:
    (I also had these types of errors because I had a typeo in my environment variables, I also got error code 407 at times because I had accidentally unset the variables)
  6. Howto sections on

5 thoughts on “Make Macports work behind proxy

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s