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
“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.
Bellow that line insert this line which will tell Macports to go fetch the daily tarball over http
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:
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
- 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/
- Alex’s blog: http://www.oconnoat.com/blog/2009/03/18/macports-through-a-proxy/
- Joe Di Pole’s blog: https://blogs.oracle.com/dipol/entry/installing_macports_behind_a_proxy
- Some macports ticket: http://trac.macports.org/ticket/13158
- 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)
- Howto sections on trac.macports.org