October 5, 2007
How To: Install Macports
Every once in a while you’ll here or read about an absolutely awesome command line utility or X11 program that you must have. After consulting the great Oracle, Google you find that the program you want is in Macports which for those who are not comfortable at the command line may cause some issues. Fear not though. Here is a very newbie guide to installing it.
Caution! This How To includes typing commands at the command line. When possible I’ve included the exact command that you should type. Simply cut and paste it, then hit enter and it should work. If not feel free to leave a comment and I’ll help out, or find your local Apple Guru.
First a bit of history. Macports, like a lot of OSX got it’s start in the FreeBSD Project which is a Unix derivative. Originally called DarwinPorts after Apple’s OS, Darwin. (Probablly some sort of evolution joke there?) Like the FreeBSD Ports before it, it allowed System Admins and users to easily install Unix applications from the command line with a simple command or two. Macports brings that all to OSX and is an essential part of making it a true Unix operating system.
Installing Mac Ports:
Step One: Install XCode
If you have the original install disc, a Tiger Upgrade disc, or even Leopard pop it in your drive and run Optional Installs. Note that in the default view of the OS disc you need to scroll down to find this file. Apple has done a pretty good job trying to keep things easy and unconfusing, but it took me about thirty Tiger upgrades before I noticed that the window scrolled down.

If for some reason you do not have this disc, never fear. Xcode can be downloaded for free from the Apple Developer Connection. You will need to sign up for ADC, but that is not a big deal. It’s 888MB in size so the download may take a while.
Step Two: Installing MacPorts
Grab the MacPorts installer from this page. If you’re running OSX 10.4 or higher you want to get MacPorts-1.5.0-10.4.dmg. This is a very small install as it’s actually all text files. Despite that it may seem like it takes a while to install. Simply continue through all the prompts until it’s done!

This is where things may get a little scarey. We need to use the Terminal or Command Prompt to edit a file called .profile in your user directory.
Open up Terminal. It’s hidden under Utilities in your Applications Folder. You can also get to it by typing term into Spotlight and clicking it under applications.
Type (or cut and paste) /Applications/TextEdit.app/Contents/MacOS/TextEdit .profile
Make sure to get the period before profile or this will not work.


You should see a less pretty version of the above.
You can also type: env
Look for the line that says: PATH=/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin (or really similiar)
If both of these are there then you’re good.
Step Four: Telling X11 about MacPorts (Optional)
This step is Optional but may make X11 a little easier to use in the future.
Type in: sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/X11/xinit/xinitrc
You’ll see a prompt asking for your password. If your user is the Administrator (it is usually by default) type in your login password.
Right before the line that says userresources=$HOME/.Xresources, type in: source ~/.profile
Save and Exit
Step Five: Update MacPorts (Optional)
At this point you’ve officially got MacPorts installed. But one last thing may need to be done.
Type: sudo port -d selfupdate
Enter your password again if it asks. A lot of test will scroll by, this will update MacPorts to the latest version if needed.
Step Six: Installing Ports
At this point the instructions are going to become vauge. If you got this far you probably had a specific port or package you wanted to install. Refer to the instructions of that application for specific install directions.
You can also use the command: port search
Once you’ve found the package name, install it by typing: sudo port install
Troubleshooting:
If you get this error message: Error executing darwin_8: invalid command name “configure.compiler”
You need to reinstall XCode again.
If you get: state is not writable – check permission on port directory
You need to run the install as Administrator by using the sudo command at the begining.
Please leave comments and let me know if you want more tutorials like this.
*update* These directions are Tiger only. Leopard does not work, see the comments below.
Great tutorial, thanks! Managed to get it set up, but had a bit of a problem with step 4, apparently file 'xinitrc' did not exist. TextEdit opened, but was blank, so I just skipped that step!
I'd highly suggest you still create the xinitrc file. Programs like Gimp that use the X11 front end will need it.
Porticus has been released. It's a GUI front end for MacPorts making life just a little bit easier.
On the step that involves editing xinitrc, I get error saying the file does not exist. I ran standard install of the developer tools from my leopard disc. I don't know what's up.
yash: The instructions on this page are correct for Tiger, but not for Leopard.
On Leopard, the DISPLAY environment is set without changing .profile (in fact changing display to 0:0 breaks things), and the file /etc/X11/xinit/xinitrc just simply does not exist, although I do not know which mechanism replaces it.
Thank you for pointing this out. These directions are for Tiger only. I've not had a chance to run Macports on Leopard yet, but I'll update these instructions once I do.
Hello. The step by step is great. I got stuck at (Type in: sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/X11/xinit/xinitrc). I got the prompt xinitrc do not exist. Who to creat it. Thanks for the help.
J
Hi Jes,
Do you have the /etc/X11/xinit folder? The sudo command should have automatically created the xinitrc file for you. You can also use TextEdit to create file anywhere (such as /Users/Username/Documents and then copy it over.
You may need to enable the Root user too.
Hello Rick,
Thanks for your quick answer. I dont think i have the folder in question. I have to specifie that I just did the transition from PC to Mac 2 months ago. Therfor i am in the learning process. Could you be more specific on the action i should execut in order to complete the instalation on my Macpro. Thanks.
In Terminal: mkdir /etc/X11/xinit/ if you're running Tiger. If you're on Leopard you might be able to skip this step.
i got stuck in /Applications/TextEdit.app/Contents/MacOS/TextEdit .profile is says that such file doesn't exist =/ and i have installed the X11 and the Xcode tools, what else can i do?
HI Katherine, do /Applications/TextEdit.app/Contents/MacOS/TextEdit Copy and paste the .profile example from above, then save the file as .profile. That should get you going.
I have the same problem as 16. Katherine
and I want to know save .profile where?
under home?
thanks~~
thanks~
I think I have fixed it.
Thank you very much! your article has helped a lot~~
I am having the same problem Qiao. Where do I save the .profile file? Also what type of file should it be saved as?
The .profile file should be in your /User Folder.
i also got stuck in /Applications/TextEdit.app/Contents/MacOS/TextEdit .profile is says that such file doesn’t exist, tried to copy paste the text from the example but doesnt let me save the text to "." its reserved for system. Please help can install macport on leopard
Save it with out the period then rename it in terminal. (using the mv command)
I am trying to install mac ports 1.7.0 into my computer and am having difficulties I downloaded the Xcode 3.1.2 developer tools for Mac OS X v10.5 I do not know how to open either of these down loads they do not open in you typical manner when clicked on usually when downloading any software on to my computer it has the installer which then has you drag an icon to the applications and you then can place an icon on your dock and it automatically opens and runs from there. with MacPorts it is an icon of a box and when clicked on it keeps going through the install process it shows it installed successfully I want to open the application and run a file how do I do this?
If you could walk me through this process step by step it would be greatly appreciated.
Thanks
Maureen
Hi Maureen, If I'm reading what you said, you have Mac Ports already installed. Mac Ports itself does not open any files, rather it allows you to install other software such as Gimp, CFEngine, and thousands more. After you've got it installed you open up terminal then type "port install packagename"
Hi Rick
i'm having problems installing macports on snow leopard. (I'm a Mac newbie trying to install Macports, to boot, I am new to working with programs, command lines, etc.)
I installed xcode with no problems then moved onto Macports where the install went perfectly. i attempted to create the new shell environment, but came across multiple conflicting directions. I tried a couple commands, getting an access denied response and other times being asked for a password. When i provided a password it simply took me to the user$ command.
i did the env command then an uninstall of Macports to start over. once i reinstalled MP and typed a couple commands and provided my password. Now env looks like this :
Last login: Wed Oct 28 14:20:37 on console
users-macbook:~ user$ env
TERM_PROGRAM=Apple_Terminal
TERM=xterm-color
SHELL=/bin/bash
TMPDIR=/var/folders/1y/1yB+HZUxEiu8yLC2XrbFUE+++TI/-Tmp-/
Apple_PubSub_Socket_Render=/tmp/launch-zSUZ7D/Render
TERM_PROGRAM_VERSION=272
USER=user
COMMAND_MODE=unix2003
SSH_AUTH_SOCK=/tmp/launch-RBWfmE/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0:0
PATH=/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
PWD=/Users/user
LANG=en_US.UTF-8
SHLVL=1
HOME=/Users/user
LOGNAME=user
DISPLAY=/tmp/launch-Usc0EL/:0
_=/usr/bin/env
users-macbook:~ user$ /Applications/TextEdit.app/Contents/MacOS/TextEdit .profile
You can see the Path= line is quite long and ends in /X11/bin.
How much did I screw up and where do i go from here?
Path command was cut off. It looks like this:
PATH=/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
The path is a variable length depending on your (and the operating systems) needs. What you have there is fine. Just go on with the next step.
.profile doesn’t exist nor does a .bash_profile. Do i need to create on in my $HOME directory?
i can see one in /etc/profile which says it is used as a system wide .profile for sh(1).
Not sure how to complete this step and which i file i should be editing?