MacPorts is a package management system that allows you to install various free and open source programs on your Mac. This blog post will take you through step by step instructions of installing MacPosrts and show you the most important commands to get you started.
Before you can install and use MacPorts you must have Xcode installed on your Mac. To install Xcode open AppStore, search for Xcode and install it – it’s a free download. The installation will take some time because Xcode is more then 2GB download.
When the download and installation is finished, start Xcode, agree to the license agreement, enter your password and it will start installing components.
This step will take another few minutes to finish. When all the components are installed the Xcode will start automatically.
We don’t need it running so you can close it. The next step is to install Xcode Command Line Tools. To do that start the Terminal.
and issue command:
$ xcode-select --install
In the message window click Install and agree to license agreement. The command line tools will start installing. When they are installed we have all the prerequisites to start MacPorts installation.
Go to MacPorts website MacPorts and click Installing MacPorts link on the left menu. In the Quick Start section click on MacPorts version for your operating system. If you don’t know what Mac OS X version you are running click Apple logo in the top left corner of your screen and select About This Mac.
Download the version of MacPorts that matches your OS X version. When the download is done run the installer
Go through all the installation steps (you will have to put your password again). When the installation finishes you should reopen the Terminal get environment variables updated. Now we have everything we need to start using MacPorts.
To confirm the installation succeed run below command in the Terminal:
$ port version Version: 2.2.1
It should give you the currently installed version of MacPorts. If you get an error message it means you did not run it in new Terminal or the installation did not succeeded.
It’s time to go over some most important
$ port list
list command will give you the listing of all available ports you can install on your Mac. The first column is the port name – this is the name you will be using to install or uninstall ports on your system. The second one is the current version of the program in MacPorts. The list of all ports is cool but not very useful. Usually when you are trying to install something you would like to search for it. For that we use
port search. For example, to search for Git you issue the following command:
$ port search git
This will list all the ports that have string
git present in either the name or description of the port. You will get a lot of results but we are only interested in
Once you find the program you are interested in you will probably want to install it. But first let’s check something really important. What are the dependencies for Git.
$ port info git-core
This command should give you an output similar to this:
git-core @22.214.171.124 (devel) Variants: bash_completion, [+]credential_osxkeychain, [+]doc, gitweb, [+]pcre, python26, [+]python27, svn, universal Description: Git is a fast, scalable, distributed open source version control system focusing on speed and efficiency. Homepage: http://git-scm.com/ Library Dependencies: perl5.12, curl, zlib, openssl, expat, libiconv, python27, pcre Runtime Dependencies: rsync, p5.12-error, p5.12-term-readkey Platforms: darwin License: GPL-2 LGPL-2.1+ Maintainers: email@example.com
Take a look at the lines Library Dependencies and Runtime Dependencies. Those are the other ports that Git is dependent on. In another words to use Git you have to have them installed as well. But you don’t have to do it manually. The beauty of MacPorts package management is that when you are trying to install a program that has dependencies that you don’t have, the port will first download, configure and install them before installing the port you asked for. This saves a lot of time and makes using MacPorts pleasant. Before we install Git let’s check which ports we already have installed. To do that you use command:
$ port installed No ports are installed
On the fresh install like ours you should get a message that there is no ports installed. OK lets install Git:
$ sudo port install git-core
Notice that you have to use
sudo. You need it because
port install puts all ports in
/opt/local/ directory by default and for that you need administrator (root) privileges. After issuing this command, port will check Git dependencies and start downloading, compiling and installing. Once all the dependencies are installed it will download, compile and install Git. Depending on your computer and Internet speed it will take from few seconds to couple of minutes. The final result on your Terminal screen should look like this:
port installed command right now should give you a list of all packages that have been installed.
To update MacPorts and its database you should run below command regularly:
$ sudo port selfupdate
This will update port and MacPorts database to the newest version. To see if any of your programs needs updating use:
$ port outdated
It will list all the ports that could be updated to new versions. To upgrade one of the ports use upgrade command:
$ sudo port upgrade port-name
Upgrading ports one by one is no fun. That’s why there is also command:
$ sudo port upgrade outdated
Which will update all outdated ports to the newest versions. Notice that
selfupdate have to be used with
Uninstalling ports is as easy as installing them. If you want to uninstall a program you no longer use, issue:
$ sudo port uninstall program-name
That’s it! Now you know the basic port commands. If you like the post / video tutorial make sure to give me thumbs up on YouTube! In the next post I will show you how to install and configure Apache web server from MacPorts.