---
title: "Ubuntu系统上svn的安装与配置"
author: "baoweiwei"
date: "2012-05-15T21:16:48Z"
tags: ["Java", "Tomcat", "Ubuntu"]
categories: ["研发管理"]
slug: "ubuntu-svn"
draft: false
lastmod: "2012-05-15T21:20:05Z"
id: 1531041
url: "https://baoweiwei.iteye.com/blog/1531041"
---

1 安装Subversion package: \[code="shell"] $ sudo apt-get install subversion \[/code] 2 建立代码库 为代码库创建文件夹 \[code="shell"] $ sudo mkdir /usr/local/svn \[/code] 据说在/home/svn目录下面亦可，但没有试过。 \[code="shell"] $ sudo mkdir /usr/local/svn/repos \[/code] 3 为了权限管理，建立用户组 \[code="shell"] $ sudo groupadd svn \[/code] 改变/usr/local/svn/repos的用户组属性 \[code="shell"] $ sudo chgrp svn /usr/local/svn/repos \[/code] 增加组内成员权限 \[code="shell"] $ sudo chmod g+w /usr/local/svn/repos \[/code] 最为重要一点，让代码库中任何新建的文件或者文件夹都保留这种权限设置： \[code="shell"] $ sudo chmod g+s /usr/local/svn/repos \[/code] 把你自己的用户名加入到svn中： \[code="shell"] $ sudo usermod -a -G svn bupt \[/code] 然后logout，注销后再次进入，生效 可以查看一下： \[code="shell"] $ groups \[/code] 如果添加其他用户，可以使用以下命令： \[code="shell"] $ sudo usermod -a -G svn ben $ sudo usermod -a -G svn ubuntu \[/code] 4 创建一个测试代码库 设置端口002 \[code="shell"] $ umask 002 \[/code] 创建 \[code="shell"] $ svnadmin create /usr/local/svn/repos/test \[/code] 恢复端口022 \[code="shell"] $ umask 022 \[/code] 5 检出并修改提交 检出 \[code="shell"] $ svn checkout file:///usr/local/svn/repos/test Checked out revision 0. \[/code] 转到工作副本，并加以修改 \[code="shell"] $ cd test $ echo 'Hello, World!' &gt; hello.txt \[/code] 添加 \[code="shell"] $ svn add hello.txt A hello.txt \[/code] 提交 \[code="shell"] $ svn commit -m "Added a 'hello world' text file." Adding hello.txt Transmitting file data . Committed revision 1. \[/code] 6 通过svn协议访问代码库 创建用户列表 \[code="shell"] $ sudo gedit /usr/local/svn/passwd-team \[/code] 形如：等号左边用户名，右边密码 \[code="shell"] \[users] michal = somepassword jimmy = anotherpassword craig = yetanotherpassword \[/code] 改变文件权限，提高安全性： \[code="shell"] $ sudo chmod 600 /usr/local/svn/passwd-team \[/code] 打开test代码库的配置文件： \[code="shell"] $ gedit /usr/local/svn/repos/test/conf/svnserve.conf \[/code] 统统删掉，写成 \[code="shell"] \[general] anon-access = none password-db = /usr/local/svn/passwd-team realm = Team \[/code] 启动svnserve. \[code="shell"] $ sudo svnserve -d --foreground -r /usr/local/svn/repos \[/code] 7 可以测试访问 ip根据实际情况而定 \[code="shell"] $ svn checkout svn://192.168.10.11/test --username jimmy \[/code] 提示输入用户名 \[code="shell"] Authentication realm: Team Password for 'jimmy': \[/code] 输入之后，变可以检出： \[code="shell"] A test/hello.txt Checked out revision 1. \[/code] 转到工作副本，修改 \[code="shell"] $ cd test $ gedit hello.txt \[/code] 提交 \[code="shell"] $ svn commit -m "Modified the hello.txt file." Sending hello.txt Transmitting file data . Committed revision 2. \[/code] 此外可以通过ssl访问，也可以通过apache http访问，这里不再赘述请查阅： \[url]http://odyniec.net/articles/ubuntu-subversion-server/\[/url] 8 eclipse插件 如果使用eclipse开发工具，可以安装subclipse作为插件，安装完后，进入window的svn资源库，创建资源，然后按提示输入用户名和密码。 需要注意的是，如果建立tomcat上的web工程，工程目录下的.settings文件夹里，打开org.eclipse.wst.common.project.facet.core.xml文件，其内容是：\[code="xml"] \[/code] 发布到SVN上，其他人进行同步的时候就会出现问题，由于版本不同，一般都出现如下错误： Target runtime Apache Tomcat 7.0 is not defined 只需将上述xml文件改为： \[code="xml"] \[/code] 即可。