Saturday, February 18, 2012

Install SVN on Mac OS X


Install SVN Repository

Installing OS X developer tools makes available a Subversion full installation.
The installed version is 1.6.16, not the most up to date version, but good enough for the normal use.

To check your installation open a terminal and type:

svn --version


Create a subversion repository

To create a repository, open a terminal:

# Create a folder to store repositories
sudo mkdir /opt/svnrepos

# Change the owner to enable write on repository
sudo chown username /opt/svnrepos

# Create the svn repository
svnadmin create /opt/svnrepos/myrepo


To refer to the new created repository, use the following URL:

URL: file:///opt/svnrepos/myrepo

Of course, you can select any folder to use as repository.
It's enough to have full permissions on it.

A very good and open source Mac GUI to subversion is:

- svnx

To install svnx, download and open the dmg file and drop the svnx icon on the Application folder.

svnXopen.sh

If you want to specify the default editor(s) used to open files, just copy svnXopen.sh (from the disc image) into ~/.subversion/ and modify it there.
[svnXopen.sh is (initially) identical to Resource/open.sh but, if it exists, it overrides Resource/open.sh.]

Getting SVN to run on Apache


You can enable your Apache installation to access svn repository. Apache runs as user www, so, you need to enable access to your repository folder to this user.
# Enable acces from other users to repository folder
sudo chmod -R 777 /opt/svnrepos


You need to modify http.conf file to add a statement to load the svn dav module and to enable a location URL for svn. Also, un-comment php Load module to enable PHP.
# Modify http.conf file at /private/etc/apache2/
sudo nano /private/etc/apache2/httpd.conf

...
LoadModule alias_module libexec/apache2/mod_alias.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
# Un-comment next line to use WebSVN
#LoadModule php5_module libexec/apache2/libphp5.so

# Add this line
LoadModule dav_svn_module libexec/apache2/mod_dav_svn.so

#Apple specific modules
...

...
# Locate the following section and add a new entry
<IfDefine !MACOSXSERVER>
<IfDefine WEBSHARING_ON>

#SVN repository entry
<Location /svn>
     DAV svn
     SVNParentPath /opt/svnrepos
</Location>
...

You must be shure to add the:

LoadModule dav_svn_module libexec/apache2/mod_dav_svn.so

line after the dav module:

LoadModule dav_fs_module libexec/apache2/mod_dav_fs.so

or you will get the following error trying to start Apache:

Cannot load /usr/libexec/apache2/mod_dav_svn.so into server: dlopen(/usr/libexec/apache2/mod_dav_svn.so, 10): Symbol not found: _dav_do_find_liveprop

Now, if you open a browser and access: http://localhost/svn/myrepo you will be able to browse it.

WebSVN


WebSVN is a nice HTTP front end for your svn repository, download from here.
Make shure that you enabled PHP un-commenting line:
#LoadModule php5_module libexec/apache2/libphp5.so
in httpd.conf.
Unzip on /opt/servers/websvn-2.3.3 and make a symlink on the HTTP Server Document root:
# Copy disconfig.php as config.php
cd /Library/WebServer/Documents/
sudo ln -s /opt/servers/websvn-2.3.3 websvn
Create and edit a config file for WebSVN:
# Create a link to WebSVN
cd /opt/servers/websvn-2.3.3/include
cp distconfig.php config.php
nano config.php

# Locate and change this line:
// $config->parentPath('Path/to/parent (e.g. c:\\svn)');

# Change to:
$config->parentPath('/opt/svnrepos');

# Restart HTTP Server
sudo apachectl restart

# or go to System Preferences -> Sharing and unset and set Web Sharing

Updating SVN version

There is no easy way (afaik) to update the Subversion pre-installed version. It's more easy to install a new one in parallel and point to it.

Download a vanilla Subversion command line client and server from WANdisco who provides a certified binaries package (These packages are provided for advanced users, editing of configuration files is required), or download from Collabnet Community Downloads (you need to register at Collabnet).
Download Subversion 1.7.3 for OSX 10.7.x and install it. Everything will be installed in /opt/subversion so to use the new version you need to set your path to point to /opt/subversion/bin.

No comments:

Post a Comment