<- Back to the HOWTO section

How to install an older version of a port

  • Audience: Anyone needing an older version of a port than is currently available in the repository or installed on their machine
  • Requires: MacPorts >= 1.7


MacPorts maintainers strive to give you the latest version of software in each port, but you may wish to use an older version for various reasons. How to do this depends on whether you still have the older version installed.

Installing an older version of a port is not the intended way to use MacPorts, is not usually recommended, and may cause various problems. It's fine to do this in the course of trying to identify a problem, but once you have determined that a newer version is broken and that an older version works, please inform the developers of the affected software of the problem so that they can fix it, so that you can soon go back to using the latest versions of the software.

Reactivating an older version that's still installed

When you upgrade an installed port, MacPorts deactivates the older version but keeps it installed. For example, assume tcl @8.4.16_0 is installed:

$ port installed tcl 
The following ports are currently installed:
  tcl @8.4.16_0 (active)

When you upgrade, a newer version of tcl will be installed and activated, while tcl @8.4.16_0 will remain installed but will be deactivated:

$ sudo port upgrade tcl
$ port installed tcl 
The following ports are currently installed:
  tcl @8.4.16_0
  tcl @8.5.0_0 (active)

As long as it is still installed, you can reactivate tcl @8.4.16_0, which will automatically deactivate the active version first:

$ sudo port activate tcl @8.4.16_0
--->  Deactivating tcl @8.5.0_0
--->  Activating tcl @8.4.16_0

And similarly you can go back to the newer version.

Once you're confident the new version works to your satisfaction, you can uninstall the old one to reclaim disk space:

$ sudo port uninstall tcl @8.4.16_0

Note: if you used the -u flag when you upgraded the port (i.e. sudo port -u upgrade tcl), MacPorts would uninstall the inactive versions after activating the latest one, so you would not be able to reactivate them later. Use -u when you know in advance that you will not want to go back to an older version, or you don't mind taking the extra steps below to reinstall the older version later if needed.

(Re)installing an older version that's no longer installed

If you want to go back to an older version after you've already uninstalled it, or to install an older version of a port that predates when you first installed it, you can do so by manually downloading the older version of the portfile and any associated files from the MacPorts Git repository.

Step 1: Find the right commit

To install an older version of the port, you'll have to get the necessary files from the repository. Browse the repository to find the directory of the port you want, then use the History button in the upper right to find the older version that you want to install. For example, if you wanted to install the older 8.4.16 version of tcl, browse to the lang/tcl directory and look at its history. Here you'll note that tcl was updated to 8.5.0 in !345f962, so you want the commit before that, which was !686ea4f. If desired, you can click the <> link in the history (not the !686ea4f link) to see the directory as it existed in that commit.

Step 2: Get the port directory

In the Terminal, using the commit hash, port category and port name, check out the port's directory at the desired commit using the git command:

$ git clone --single-branch
$ cd macports-ports
$ git checkout 686ea4fa0fddeb03fdf2fc04dded68e05181bc95

This creates a "macports-ports" directory in your current location, and populates that with a complete copy of the ports tree as it existed at the specified point in history. Replace "686ea4fa0fddeb03fdf2fc04dded68e05181bc95" with the commit you're interested in.

Note: Git is included with Xcode 4.1 and later but you may want to get a newer version by installing the git port; Xcode 4.0 and earlier do not include git, so users of those versions must install the port:

$ sudo port install git

Note: MacPorts usually runs under a separate "macports" user account with reduced privileges, so you must check out the port's directory in a place where the macports user can read them. The directories Desktop, Documents, Downloads, Library, Movies, Music, and Pictures, which OS X created in your home directory when your user account was created, have permissions that prevent other users (including the macports user) from looking inside them, so these are not suitable locations. Using an unsuitable location will result in an error message like Error: Unable to execute port: Could not open file: /Users/username/Desktop/portname/Portfile. So instead, create a new directory in your home directory (such as "macports") in which to store these port directories. Or you could create another directory elsewhere (e.g. at the root of your hard drive) for this purpose. If you don't mind the OS deleting these files after a few days, or after a restart, you could put them in /tmp. If you really want to put the port directory in one of the mentioned directories in your home directory, and you don't mind other users on your system reading your files (e.g. if your computer is used by only one person), you could change the permissions of the desired directory from 0700 (drwx------) to 0755 (drwxr-xr-x).

Step 3: Build the downloaded port

Finally, change to the directory you checked out with Git (which contains the Portfile) and install the port, omitting the port name:

$ cd lang/tcl
$ sudo port install

Specifying a variant

To enable a variant, specify it as usual. For example, to install the port in the current directory enabling the quartz variant:

$ sudo port install +quartz

To disable a variant that's on by default, you must also first use the -- argument. For example, to install the port in the current directory disabling the x11 variant:

$ sudo port install -- -x11

Specifying a subport

Some Portfiles—including those for python modules, perl modules, php modules, and others—contain subports. For example, a python module has subports for each version of Python it supports. To specify which subport you want, set the "subport" variable. For example to install the py27-pylint subport of the py-pylint portfile:

$ cd py-pylint
$ sudo port install subport=py27-pylint

Make sure you specify the subport exactly as shown at the top of the output of port info. As of version 2.4.3, MacPorts will consider it an error if you misspell a subport name or request a subport that does not exist. Although MacPorts usually treats port and subport names case-insensitively, case is significant when specifying the subport name in this way.

Working with the older ports

Once the port is installed, be careful about using the portname with other commands.

$ sudo port install tcl

will install the _current_ version of tcl, even though you are in a directory with an older version of tcl. Leave off the port name to install the older version from the current directory.

Similarly for other commands like port logfile, there is a difference between specifying the name of a port and leaving it out. Specifying the version number of the older port doesn't work; many port commands ignore a version specifier.

$ port logfile MPlayer
$ port logfile        
$ port logfile MPlayer @1.1_8

<- Back to the HOWTO section

Last modified 2 years ago Last modified on Feb 21, 2022, 7:38:41 PM