Make Macports work behind proxy


I ended up struggling for months to get Macports to work and tried every installation method in www.macports.org 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: http://www.macports.org/install.php

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/rsync.macports.org/release/tarballs
—> Updating MacPorts base sources using rsync
rsync: failed to connect to rsync.macports.org: 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://rsync.macports.org/release/tarballs/base.tar /opt/local/var/macports/sources/rsync.macports.org/release/tarballs
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://rsync.macports.org/release/tarballs/ports.tar [default]

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

http://www.macports.org/files/ports.tar.gz [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

env

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

^_^

References:

  1. John DeStefano’s blog (also has method to use svn to update port tree): http://destefano.wordpress.com/2011/03/18/macports-behind-a-proxy/
  2. Alex’s blog: http://www.oconnoat.com/blog/2009/03/18/macports-through-a-proxy/
  3. Joe Di Pole’s blog: https://blogs.oracle.com/dipol/entry/installing_macports_behind_a_proxy
  4. Some macports ticket: http://trac.macports.org/ticket/13158
  5. Some really sad macports ticket: http://trac.macports.org/ticket/29484
    (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 trac.macports.org
    1. https://trac.macports.org/wiki/howto/PortTreeTarball
    2. https://trac.macports.org/wiki/howto/SyncingWithSVN
Advertisements

5 thoughts on “Make Macports work behind proxy

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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