MacPorts

From Segfault
Jump to: navigation, search

Usage

Install MacPorts to get some useful software on your Mac :-)

port install dos2unix iftop iperf nagios-plugins nrpe pv rsync smartmontools stunnel unrar wget xz

Variants

Some packages are installing many dependencies, check out port variants PKG before installing:

$ port variants git-core
git-core has the variants:
   bash_completion: Completion support for bash
[+]credential_osxkeychain: Install git credential-osxkeychain utility from contrib
[+]doc: Install HTML and plaintext documentation
   gitweb: Install gitweb.cgi
[+]pcre
   python26: Use Python 2.6
     * conflicts with python27
[+]python27: Use Python 2.7
     * conflicts with python26
   svn: Bi-directional subversion repository support
   universal: Build for multiple architectures

$ port install git-core +bash_completion -credential_osxkeychain -doc

bash-completion

Let's say we want to have bash-completion but we don't want to install bash4 from MacPorts:

git clone git://git.debian.org/git/bash-completion/bash-completion.git bash-completion-git
cd bash-completion-git

However, support for Bash v3.2 was removed in 2010[1][2], so let's checkout an earlier version:

$ git describe --contains 314cc0f13a9c8001f73e52bc00c1b8183f9d701e
1.2~8^2~80^2~1
$ git checkout -b local-3.2 1.2~8^2~80^2~1^              # i.e. one version before 3.2 support was dropped

And build it:

./autogen.sh  && ./configure --prefix=/opt/bash-completion
make && make install
sudo ln -s /opt/bash-completion/etc/bash_completion /etc/bash_completion
sudo ln -s /opt/bash-completion/etc/bash_completion.d /etc/bash_completion.d
sudo ln -s /opt/bash-completion/etc/profile.d /etc/profile.d

And that should be it. We now have preliminary bash-completion:

$ . /opt/bash-completion/etc/bash_completion
$ ssh <TAB><TAB>
host0 host2 host3

Multiple ports

Sometimes more than one version of a package is available. When a package depends on e.g. perl5, we'd like to have perl5.14 installed instead of perl5.12:

$ port install perl5 +perl5_14
$ port echo inactive 
perl5                          @5.12.3_1+perl5_12 

$ port uninstall perl5@5.12.3_1+perl5_12


But what if some other port depends on this port and we cannot uninstall it? Let's say we have two versions of xz installed:

$ port echo installed | grep xz
xz                             @5.0.4_0
xz-devel                       @5.1.1alpha_0

And the older version is currently active:

$ xz --version
xz (XZ Utils) 5.0.4
liblzma 5.0.4

But we want the newer version being the default. We try to uninstall "xz" first, so that "xz-devel" might take over:

$ port uninstall xz
--->  Unable to uninstall xz @5.0.4_0, the following ports depend on it:
--->    tiff @4.0.3_1
--->    libxml2 @2.9.0_0
Error: org.macports.uninstall for port xz returned: Please uninstall the ports that depend on xz first.
Please see the log file for port xz for details:
   /opt/local/var/macports/logs/_opt_local_var_macports_registry_portfiles_xz_5.0.4_0/xz/main.log
Warning: Failed to execute portfile from registry for xz @5.0.4_0
--->  Unable to uninstall xz @5.0.4_0, the following ports depend on it:
--->    tiff @4.0.3_1
--->    libxml2 @2.9.0_0
Error: port uninstall failed: Please uninstall the ports that depend on xz first.

Hm, this didn't go so well. Let's try to activate the newer version then:

$ port activate xz-devel
--->  Computing dependencies for xz-devel
--->  Activating xz-devel @5.1.1alpha_0
Error: org.macports.activate for port xz-devel returned: Image error: /opt/local/bin/lzcat is being 
used by the active xz port.  Please deactivate this port first, or use 'port -f activate xz-devel' to 
force the activation.
Please see the log file for port xz-devel for details:
   /opt/local/var/macports/logs/_opt_local_var_macports_registry_portfiles_xz-devel_5.1.1alpha_0/xz-devel/main.log
Warning: Failed to execute portfile from registry for xz-devel @5.1.1alpha_0
--->  Activating xz-devel @5.1.1alpha_0
Error: port activate failed: Image error: /opt/local/bin/lzcat is being used by the active xz port. 
Please deactivate this port first, or use 'port -f activate xz-devel' to force the activation.

OK, let's force it:

$ port -f activate xz-devel
--->  Computing dependencies for xz-devel
--->  Activating xz-devel @5.1.1alpha_0
Warning: File /opt/local/bin/lzcat already exists.  Moving to: /opt/local/bin/lzcat.mp_1365971561.
Warning: File /opt/local/bin/lzcmp already exists.  Moving to: /opt/local/bin/lzcmp.mp_1365971561.
[...]
--->  Cleaning xz-devel
$ xz --version
xz (XZ Utils) 5.1.1alpha
liblzma 5.1.1alpha

But there are some leftovers now:

$ find /opt/local/ -name "*mp_1365971561" | wc -l
81

Let's see if every leftover has an actual file left:

$ find /opt/local/ -name "*mp_1365971561" | while read f
        do ls -l ${f%.mp_1365971561} > /dev/null
done
[no output]

Do some housekeeping:

$ find /opt/local/ -name "*mp_1365971561" -ls -delete

Clean up

Uninstall all inactive ports:

$ port echo installed | grep xz
xz                             @5.0.7_0
xz                             @5.2.1_0

$ port echo active | grep xz
xz                             @5.2.1_0

$ port echo inactive | awk '{print $1$2}' | xargs port uninstall
[...]
--->  Uninstalling xz @5.0.7_0
--->  Cleaning xz

Queries

Available packages:

$ port echo all | wc -l
  13697

Ther's also port list, but it's kinda slow, though the output contains a short description:

$ time port echo installed
real    0m0.248s
user    0m0.151s
sys     0m0.065s

$ time port list installed
real    0m59.140s
user    0m53.084s
sys     0m1.965s

Links

References