MAC – Upgrading MacPorts

Wondering why is this necessary? Citing MacPorts,

An installation of MacPorts and the ports installed by it are only designed to work on a single OS release and a single CPU architecture. If you upgrade to a new OS version (e.g. from Tiger to Leopard) or migrate to a new machine with a different type of CPU (e.g. PowerPC to Intel), you may get lucky and have your ports keep working, but in general, things will break.

Fairly recently, my Mac underwent an upgrade from Leopard to Snow Leopard and not knowing that I needed to upgrade MacPorts to keep things sane, I tried installing Qt Octave – an open source equivalent of MATLAB [more about this in a subsequent post]. Needless to say, things started breaking and result was a [lot] more time consuming process of upgrading MacPorts.

Part #0. Upgrading/Re-installing XCode

First step is to download XCode 3 for Snow Leopard from Apple Developer Connection [one needs to create an account to download the DMG but it’s free]. One needs to ensure that the optional components for command line development are installed as well (Unix Development in the XCode 3.x installer). Unfortunately, XCode is not upgraded automagically during the regular/routine software updates but the installation went smooth and just for good measure, I rebooted the machine.

Part #1. Upgrading MacPorts

Download the appropriate .pkg file from MacPorts and complete the installation of base package. This went [should go] smooth as well. Once the installation is complete, run the following command in a terminal:

sudo port -v selfupdate

If this results in an error port: command not found, update the definition of PATH variable [in $HOME/.bashrc] to include /opt/local/bin:

export PATH="${PATH}:/opt/local/bin"

Save the $HOME/.bashrc and source it via

. $HOME/.bashrc

Part #2. Re-installing Ports

Part of this stage is really easy – make a list of installed ports and remove all the installed ports. To accomplish these:

1
2
3
sudo port installed > $HOME/installed_ports.txt
sudo port clean installed
sudo port -f uninstall installed

The most time consuming [and as such most boring/entertaining] part is re-installing all the required/active ports – one at a time – by going through $HOME/installed_ports.txt. To significantly simplify this process and reduce the associated boredom/entertainment, I did the following:

1
grep "active" $HOME/installed_ports.txt | awk -F ' ' '{print $1}' > $HOME/active_ports.txt

I read through $HOME/active_ports.txt and removed duplicate entries if any as well as retained only the highest / most recent version of any given port. I then used the following shell script, port_reinstall.sh, to install them:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#! /bin/bash
 
# BASH script to re-install previously installed ports on an Apple Mac
# The list of active ports is imported from $HOME/active_ports.txt
# and this list varies from person to person, depending on what (s)he
# has installed previously. 
#
# Gowtham, Tue Oct 20 22:23:36 EDT 2009
 
export ACTIVE_PORTS="apr
  apr-util
  aquaterm
  arpack
  atk
  autoconf
  automake
  bluefish
  bzip2
  cairo
  cmake
  coreutils
  curl
  cyrus-sasl2
  db46
  docbook-xml
  docbook-xsl
  expat
  fftw-3
  fftw-3-single
  fontconfig
  freetype
  gawk
  gcc43
  gd2
  gettext
  ghostscript
  git-core
  glib2
  gmake
  gmp
  gnome-common
  gnome-icon-theme
  gnuplot
  gperf
  gqview
  GraphicsMagick
  groff
  gsed
  gtk-doc
  gtk2
  help2man
  hicolor-icon-theme
  icon-naming-utils
  ImageMagick
  intltool
  jmol
  jpeg
  libart_lgpl
  libglade2
  libiconv
  libidn
  libpixman
  libpng
  libtool
  libxml2
  libxslt
  lzmautils
  m4
  metis
  mpfr
  ncurses
  ncursesw
  neon
  openssl
  p5-compress-raw-zlib
  p5-compress-zlib
  p5-crypt-ssleay
  p5-error
  p5-html-parser
  p5-html-tagset
  p5-io-compress-base
  p5-io-compress-zlib
  p5-libwww-perl
  p5-locale-gettext
  p5-svn-simple
  p5-term-readkey
  p5-uri
  p5-xml-namespacesupport
  p5-xml-parser
  p5-xml-sax
  p5-xml-simple
  pango
  pcre
  pdflib
  perl5.8
  pkgconfig
  plotutils
  popt
  readline
  render
  rsync
  scrollkeeper
  serf
  shared-mime-info
  sqlite3
  subversion
  subversion-perlbindings
  SuiteSparse
  teTeX
  texi2html
  texinfo
  tiff
  urw-fonts
  wget
  Xft2
  xmlcatmgr
  xorg-bigreqsproto
  xorg-inputproto
  xorg-kbproto
  xorg-libice
  xorg-libsm
  xorg-libX11
  xorg-libXau
  xorg-libXaw
  xorg-libXdmcp
  xorg-libXext
  xorg-libXmu
  xorg-libXt
  xorg-renderproto
  xorg-util-macros
  xorg-xcmiscproto
  xorg-xextproto
  xorg-xf86bigfontproto
  xorg-xproto
  xorg-xtrans
  xpm
  xrender
  zlib"
 
for x in $ACTIVE_PORTS
do
  sudo port install $x
  sleep 5
done

Once this file is saved, run this as

./port_reinstall.sh 2>&1 | tee $HOME/port_reinstall_00.txt

and keep entering password when the process demands. Once the process is completed [could take hours, depending how many ports need to be installed, their dependencies and the network speed], make sure to read through $HOME/port_reinstall_00.txt – to learn about errors messages/warnings/notification of further actions, if any. After taking care of those things, run the script again – for good measure:

./port_reinstall.sh 2>&1 | tee $HOME/port_reinstall_01.txt

This process should preferably complete within minutes and the machine should be ready to use as before.

Request

If you find errors in this approach and/or know of better [more elegant] methods to accomplish the same, please do let me [and other readers] know of it by posing them as comments. They will be greatly appreciated.

One Reply to “MAC – Upgrading MacPorts”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.