wiki:InstallingMacPortsOnUbuntuLinux

Version 9 (modified by bpdegnan (Brian Degnan), 7 weeks ago) (diff)

added some comment about certain packages and how to address them.

Installing MacPorts on Ubuntu Linux


MacPorts has been designed to be multi-platform, and it does install on Ubuntu Linux with modest modifications. Please note that at this point in time, this is a highly experimental process, and issues are expected to arise.

First, some quick notes for those familiar with Darwin; on Ubuntu:

apt is the built-in package manager, similar to "port".

"sudo apt install" is similar to "sudo port install".

"apt info" is similar to "port info"

"apt-file show" does something similar to "port contents", but the software does not have to be installed.

"dpkg -S /path/to/file" does something similar to "port provides"

To install MacPorts on Ubuntu Linux, you must first install the necessary prerequisites that are typically found on Darwin systems. At the time of writing, this was:

sudo apt install clang-14
sudo apt install clang
sudo apt install mtree-netbsd
sudo apt install tcl8.6
sudo apt install curl
sudo apt install sqlite3
sudo apt install gnustep
sudo apt install libcurl4-gnutls-dev
sudo apt install libsqlite3-dev
sudo apt install libssl-dev

or, all at once:

sudo apt install clang-14 clang mtree-netbsd tcl8.6 curl sqlite3 gnustep libcurl4-gnutls-dev libsqlite3-dev libssl-dev

Then download the macports tarball from macports.org, perhaps using the included FireFox browser, and decompress it, as per the usual Darwin instructions <https://www.macports.org/install.php#source>.

I suggest that you don't install startup items at this point in time, as this functionality is different on Ubuntu, so configure your build like this:

./configure --without-startupitems

and then

make && sudo make install

Then add the "macports" user, in the Ubuntu way:

sudo adduser --system --group --home /opt/local/var/macports/home  --disabled-password macports
sudo chown -R macports:macports /opt/local/var/macports/home

Add the macports directory to your PATH as usual, but on Ubuntu, by editing ".bashrc", for example with nano, adding a line like this:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

Also add that PATH to the sudo command's path, like this:

sudo visudo

and add it to the secure_path

Defaults  secure_path="/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

There are some differences between Darwin and Ubuntu, and to work around some of these that are not already compensated for by MacPorts base, set some defaults in macports.conf like this:

sudo gedit /opt/local/etc/macports/macports.conf

and add:

default_compilers      clang            # compiler selection is not yet working on Ubuntu, this chooses /usr/bin/clang which works best with macport's portfiles
cxx_stdlib             libstdc++        # configure.cxx_stdlib is not yet working on Ubuntu, this fills in appropriate default

Darwin and Ubuntu supply 'sed' and 'grep' in different locations, so rather than edit many Portfiles that expect it in the Darwin location, you can do this:

sudo ln -s /bin/sed /usr/bin/sed
sudo ln -s /bin/grep /usr/bin/grep

And at that point, you should be able to run normal MacPorts commands.

sudo port -v selfupdate

will update your ports tree to the current status.

And then try to install a typical port, like this:

sudo port -v install libffi

And presto:

$ port -v installed
The following ports are currently installed:
  libffi @3.2.1_0 (active) platform='linux 5' archs='x86_64' date='2020-05-02T23:25:44-0700

You can certainly expect to come across issues; MacPorts' PortFiles have largely been written to assume they are installing on Darwin, but with minor modifications to some ports, seem happy with Linux as well.

Two common issues that come up with ports on Linux are the dependence on ed and BSD's sed. Two packages on macports that tend to find all of the dependencies are ncurses and xz.

sudo apt install ed

There are few BSDSED packages on github.com that will address the sed issues that come up on ncurses.