Subverted

Box IconOne of the reasons I started this blog is to talk about some upcoming software projects that I’ve been working on. I have quite a bit more work to do before there’s anything to share, but these projects involve “peripheral” stuff that I’m working on - and that stuff is worth mentioning.

One of those “peripheral” things is getting Subversion running on Mac OS X. I’ve recently spent quite a bit of time coding - learning lots of Cocoa, testing CoreData, etc. And at this point, I need to start maintaining it better and investing some time in maintaining it. Version control is important for large projects. (Joel has some thoughts here). Not as much for one-man gigs, but I thought it would be a good experience anyway.

I found several guides around the web discussing the benefits of Subversion as well as how to install it on Mac OS X. Unfortunately, most of them seem to have been written before Tiger and they also didn’t use DarwinPorts. Or, well, James Duncan Davidson’s does, but also only covers the install. The problem with not using DarwinPorts is that the install paths are different, making it difficult to follow the instructions to the letter. Here are some excellent sources and tutorials about installing Subversion on Mac OS X - check them out:

x180 / james duncan davidson - Subversion via DarwinPorts

MacZealots.com - Using Subversion with Xcode

MacDevCenter - Making the Jump to Subversion

I started with the tutorials above, and the steps below are my notes - what I did differently, etcetera. After several hours, some troubleshooting, and some fidgeting, I’ve finally got Subversion installed. Unfortunately, I still don’t have it working in Xcode, but I’ll note that at the bottom - hopefully someone else can help me out!

Step 1: DarwinPorts

Disk IconGo to DarwinPorts and download the ports app. After the install, you should be able to open up a terminal session and run the ‘port’ command. Now it’s time to install Apache2 and Subversion. Unless you’re logged in as root, you will probably have to add ’sudo’ to your commands:

sudo port install apache2

sudo port install subversion +mod_dav_svn

sudo port install DarwinPortsStartup

DarwinPorts will download all the packages and all the packages they depend on, the unpack, compile, install, and configure each one. It may take some time depending on your internet connection speed and your computer’s horsepower. While it’s working, open another terminal window and check out the man pages for DarwinPorts. Explore some of the commands - how to activate or deactivate, what the +xxxxx variants are, how to update the ports that your installation knows about, etc. It’s a pretty powerful tool.

Step 2: Configure Subversion

Hardhat IconFirst, make yourself a repository. This is where Subversion will store its database of your files. This can technically be anywhere. MacZealots put it in the Users directory for a few reasons. I didn’t have a reason to disagree… so voila!

sudo svnadmin create /Users/Subversion

Technically, you can now start using Subversion. Most of the remaining steps have to do with setting up Apache2 to use the Subversion repository. But if you just wanted to use the svn command line tools, you can start doing that. The man pages for svn and svnadmin are a good place to start (although I think they just refer you to using svn help. Since I wanted to set up Subversion to use through Apache2, reset the owner on the Subversion directory:

sudo chown -R www /Users/Subversion

Step 3: Configure Apache2

Word IconSo this is where what I saw on my system started differing from what the MacZealots and MacDevCenter tutorials said I should see. I think this was mainly because I used DarwinPorts, but a few things might be because of newer versions of Subversion and Apache2.

Open your favorite text editor (I used TextWrangler… it’s free and it rocks.). Open /opt/local/apache2/conf/httpd.conf Now, for me, this file did not exist! However, Apache2 did install a file called httpd.conf.sample in the same directory. I opened that file and saved it as httpd.conf and made my changes there. So far, that seems to be working fine for me, so if there’s a reason I should not have done that, or if I should have edited a different file, please let me know! Most of the remaining steps in this section are identical to the MacZealots and MacDevCenter articles.

First, tell Apache2 which account it should run as. I assumed “www” and that’s who we set as the owner of the /Users/Subversion directory above. So find a line in your httpd.conf file that says:

User nobody

And change it to look like this:

#User nobody
User www

If yours already says “User www”, don’t change a thaaang!

Next, configure Apache2 to access your Subversion repository. This means making sure it loads the svn module that you installed via DarwinPorts. The install placed the file in the correct location, so all I had to do was tell apache2 about it. Find the LoadModule section of httpd.conf and add this line:

LoadModule dav_svn_module modules/mod_dav_svn.so

Next, change the port that Apache2 listens on. Remember that Mac OS X comes with a web server already installed - and it’s Apache 1.3. By default, it’s turned off. However, if you turn it on, it listens on port 80. This is the same port that Apache2 will try to listen on by default. So we’ll change it. MacZealots uses port 8800 - and again, I had no reason to do differently. Find the line in httpd.conf that says Listen 80 and make it look like this:

#Listen 80
Listen 8800

Now that Apache2 knows how to access your Subversion Repository, tell it who should have access to the repository. Add this text to the end of your httpd.conf file:


DAV svn
SVNPath AuthType Basic
AuthName “Subversion Repository”
AuthUserFile /opt/local/apache2/etc/svn-auth-file
Require valid-user

Now, whenever you try to access the repository, Apache2 will ask you for a username and password. It will check that against what it finds in svn-auth-file. Save and close httpd.conf. (TextWrangler will probably ask for a password before saving - that’s fine).

So the next step is to set up that file and add at least one username and password. Back at the command line:

sudo htpasswd -c /opt/local/apache2/etc/svn-auth-file username

Replace username with a username. I used blakeseely. It will first ask you for an administrator password (to perform the sudo) and will then ask you for a password to set for that user.

Time to start up Apache2:

sudo /opt/local/apache2/bin/apachectl start

You should be able to access your Subversion directory using the following URL:

http://localhost:8800/svn/

Because you installed DarwinPortsStartup, Apache2 should automatically start after you restart your computer.

Step 4: Everything Else

Xcode IconSteps 1 through 3 got everything installed and configured. Now it’s time for everything else:

  • Importing projects into your Subversion repository
  • Xcode integration

I haven’t had much time to play around with my install yet, so I haven’t done much with either of these. The MacZealots article has thorough descriptions of both. I started on the Xcode integration, but every time I tell Xcode to go online, I get a message saying “SCM Error: SCM could not go online. Could not reach host:localhost:8800″. If anybody knows what the problem is, please let me know.

Update: Looks like Xcode has a problem with designating the port in your URL. Hopefully it’ll get fixed in a future update. I posted a workaround here.

Update: Made a change to the svn-auth-file path - I had one wrong.

5 Responses to “Subverted”


  1. 1 Justin Williams Jul 31st, 2005 at 8:10 am

    There is a bug in Xcode 2.1 that makes Xcode not friendly with URLs with ports and usernames in the URL string. It’s on the team’s radar.

  2. 2 Nithin Nov 30th, 2005 at 12:37 pm

    Apache 2 did not automatically start on my machine until I added the following line to “/etc/hostconfig”:

    APACHE2=-YES-

  3. 3 blake May 4th, 2006 at 2:54 pm

    Ah - good reminder Nithin - you can install “DarwinPortStartup” via DarwinPorts, and that little goodie will start Apache2 for you when you start your machine!

  4. 4 Elise van Looij Oct 12th, 2006 at 1:26 am

    The text to be added to the end of the httpd.conf file should be enclosed between location tags, thus:

    DAV svn
    SVNPath

    Also SVNPath should have a value, something like /Users/repository. I can’t give good advice here because I’ve never gotten that to work (that’s why I’m reading all these blogs and pointing out omissions).

    As far as the suggestion for creating a authentication file in /opt/local/apache2/etc/svn-auth-file — that is in one of those articles you link to but have you actually tried it?
    My Darwinports Apache2 installation has no etc folder at that place, and I’ve seen others point this out to in comments to that article. I have to say I’m a bit disappointed, I thought I’d finally found someone who has the same problem I have (getting Subversion to work on a DarwinPorts installation) and who was writing from actual experience, not just copying and pasting googled stuff. Anyone who follows the steps in your article to the letter is doomed to disappointment and frustration, I’m sorry to say.

  5. 5 Alister Nov 30th, 2006 at 5:43 pm

    Thanks Blake, I’ve been hunting for a guide like this.

    Elise points out the two problems with your instructions: the missing “etc” directory and the missing Location tags.

    The missing directory is easy to fix - just create it.

    The Location tags are explained in the MacDevCenter article you’ve linked to above (towards the end of the first page).

Comments are currently closed.