Tuesday, July 21, 2009

Installing Subversion Client and Server on OS X

Installing Subversion on OS X is actually really easy, but for those of you who have not done it before it can seem like quite a task. There are many Revision Control systems out there but in my opinion SVN is well suited for the needs of just about any person or project, for those of you not too familiar with SVN or how it works, you should check out the Wikipedia link above.

All of my tutorials if you haven't noticed make use of MacPorts, if you don't have it installed already now would be a good time to install it.

First thing you want to do whenever you're installing something from MacPorts is make sure you're current. We'll do a selfupdate to upgrade existing packages and update package info.
  • dStruct:~ Matt$ sudo port selfupdate
Next up you want to install SVN via the MacPorts system.
  • dStruct:~ Matt$ sudo port install svn
We need to make sure svn is in your default path by running svn from a Terminal session.
  • dStruct:~ Matt$ svn
  • -bash: svn: command not found
So it looks like we need to update .profile with the correct path, by default MacPorts installs to /opt/local/bin and /opt/local/sbin which is not normally in the default path.
  • dStruct:~ Matt$ nano .profile
  • export PATH=/opt/local/bin:/opt/local/sbin:$PATH
You should now see the following when you run svn.
  • dStruct:~ Matt$ svn
  • Type 'svn help' for usage.
The SVN client is now ready for use, for those interested in running your own SVN Repositories to keep track of your own project or source code lets setup the SVN Server a.k.a. svnserve.

First thing to do is decide where you want your Repository located on your drive (I use ~/SVN) and then we want to create the Repository directory and it's file structure.
  • dStruct:~ Matt$ svnadmin create ~/SVN
Which should create the actual directory and setup the SVN framework inside it, including the default SVN Server configuration files in ~/SVN/conf/. It should be noted you rarely ever directly edit the files in the SVN Repository, only advanced users who know how to manipulate SVN should ever touch the files inside. However if you plan on allowing anyone remote access to your SVN Repository it would be wise to setup permissions on who can access what.

Let's do a test run and make sure the SVN Server fires up with the default settings and no authentication, and that we can check out the Repository.
  • dStruct:~ Matt$ svnserve -d -r ~/SVN/
  • dStruct:~ Matt$ svn checkout svn://dStruct/ ~/test
  • Checked out revision 0.
Ok so now we have our Repository built and we know the server works, lets setup the SVN Server to launch automatically at startup under the inetd service. We need to create a new Property List or plist and place it in /Library/LaunchDaemon so launchd knows where to find it on startup.
  • dStruct:~ Matt$ killall svnserve
  • dStruct:~ Matt$ cd /Library/LaunchDaemon
  • dStruct:LaunchDaemon Matt$ sudo nano org.tigris.subversion.svnserve.plist
And paste in the following XML, editing the 2 lines required.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

<dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>org.tigris.subversion.svnserve</string>

<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/svnserve (EDIT THIS LINE)</string>
<string>--inetd</string>

<string>--root=/Users/YourUsername/SVN (EDIT THIS LINE)</string>
</array>
<key>ServiceDescription</key>
<string>Subversion Standalone Server</string>

<key>Sockets</key>
<dict>
<key>Listeners</key>
<array>
<dict>

<key>SockFamily</key>
<string>IPv4</string>
<key>SockServiceName</key>
<string>svn</string>

<key>SockType</key>
<string>stream</string>
</dict>
<dict>
<key>SockFamily</key>

<string>IPv6</string>
<key>SockServiceName</key>
<string>svn</string>
<key>SockType</key>

<string>stream</string>
</dict>
</array>
</dict>
<key>inetdCompatibility</key>

<dict>
<key>Wait</key>
<false/>
</dict>
</dict>
</plist>
With that file saved now we need to add it to the Launch Daemon and we'll go ahead and fire it up right now manually as if we just booted up.
  • dStruct:~ Matt$ sudo launchctl load /Library/LaunchDaemon/org.tigris.subversion.svnserve.plist
  • dStruct:~ Matt$ sudo launchctl start org.tigris.subversion.svnserve
Now for the final test, lets try to check out the local Repository.
  • dStruct:~ Matt$ svn checkout svn://dStruct/ ~/test
  • Checked out revision 0.
There you go, if you ran into any issues check the reference links below, and Google is your best resource for answers, enjoy.

Version Control with Subversion
Subversion server (svnserve) on Mac OS X

1 comment:

Unknown said...

I'm not familiar how does it works but so interesting how it work, so i will study it so hard.






Arizona Payroll Services