svn Command in Linux

Introduction to Subversion (SVN) on Ubuntu 22.04

In this hands-on lab, you will delve into the world of version control by learning how to install and utilize the Subversion (SVN) system on an Ubuntu 22.04 environment. You will gain practical experience initializing a local SVN repository, committing changes to track your work, updating your local copy with the latest revisions, and reverting modifications when necessary. This tutorial covers essential SVN commands and their real-world applications, providing a solid foundation for managing source code effectively and collaborating seamlessly on projects using SVN for systemadmin tasks.

This lab begins with a step-by-step guide to installing the Subversion package on Ubuntu 22.04. It then takes you through the crucial process of initializing a local SVN repository, empowering you to manage your project files and meticulously track changes over time. You will master the art of committing new code, updating your repository to stay in sync with the latest developments, and reverting unwanted changes to maintain code integrity. This practical, hands-on experience with SVN will equip you with the fundamental skills needed to leverage this powerful version control system in your development workflows, enhancing your capabilities as a systemadmin.

Install Subversion (SVN) on Ubuntu 22.04: A Step-by-Step Guide

In this section, we will walk through the installation process for the Subversion (SVN) version control system on your Ubuntu 22.04 environment.

First, ensure your package index is up-to-date and then install the Subversion package using the following commands:

sudo apt-get update
sudo apt-get install -y subversion

Example output:

Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
...
Fetched 324 kB in 1s (324 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libapache2-mod-svn libsvn1 perl-modules-5.34 python3-subversion
Suggested packages:
  subversion-tools
The following NEW packages will be installed:
  libapache2-mod-svn libsvn1 perl-modules-5.34 python3-subversion subversion
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,197 kB of archives.
After this operation, 16.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
...

Once the installation is complete, confirm the Subversion installation by checking its version:

svn --version

Example output:

svn, version 1.14.1 (r1943681)
   compiled Aug 10 2022, 13:12:26 on x86_64-pc-linux-gnu

Copyright (C) 2022 The Apache Software Foundation.
This software consists of contributions made by many people;
see the NOTICE file for more information.

Subversion is open source software, see http://subversion.apache.org/

Subversion is now successfully installed and ready for use on your Ubuntu 22.04 system.

Creating Your First Local SVN Repository on Ubuntu 22.04

In this section, you will learn how to initialize a local Subversion (SVN) repository on your Ubuntu 22.04 system.

First, create a directory to serve as the host for your local SVN repository:

mkdir ~/project/svn-repo

Now, initialize the SVN repository within the ~/project/svn-repo directory:

cd ~/project/svn-repo
svnadmin create .

Example output:

$ cd ~/project/svn-repo
$ svnadmin create .

The svnadmin create . command initializes a brand new Subversion repository in the current directory. This is a crucial step for version control.

Next, verify the structure of the newly created repository:

ls -l ~/project/svn-repo

Example output:

total 16
drwxr-xr-x 2 labex labex 4096 Apr 12 10:12 conf
drwxr-xr-x 2 labex labex 4096 Apr 12 10:12 db
drwxr-xr-x 2 labex labex 4096 Apr 12 10:12 format
drwxr-xr-x 2 labex labex 4096 Apr 12 10:12 hooks
drwxr-xr-x 2 labex labex 4096 Apr 12 10:12 locks
-rw-r--r-- 1 labex labex   12 Apr 12 10:12 README.txt

The repository structure contains various directories and a README.txt file, which are essential for managing the repository's configuration, database, and hooks.

Your local SVN repository is now initialized and ready for action!

Mastering SVN: Committing, Updating, and Reverting Changes

In this section, you will gain practical experience with committing, updating, and reverting changes within your Subversion (SVN) repository.

First, create a new file within the SVN repository:

cd ~/project/svn-repo
echo "This is a test file." > test.txt

Now, add the newly created file to the SVN repository:

svn add test.txt

Example output:

A         test.txt

Next, commit the changes to the repository:

svn commit -m "Add test.txt file"

Example output:

Adding         test.txt
Transmitting file data .
Committed revision 1.

The svn commit command uploads your changes to the SVN repository along with a descriptive commit message, crucial for tracking changes.

Now, modify the test.txt file and then update your local working copy from the repository:

echo "Updated test file." >> test.txt
svn update

Example output:

U    test.txt
Updated to revision 2.

The svn update command downloads the latest changes from the repository and applies them to your local working copy, keeping you synchronized.

Finally, revert the changes made to the test.txt file:

svn revert test.txt
cat test.txt

Example output:

Reverted 'test.txt'
This is a test file.

The svn revert command discards any local modifications and restores the file to its last committed state.

Through these exercises, you've learned the fundamentals of committing, updating, and reverting changes within an SVN repository.

Conclusion: Mastering Subversion for Version Control

In this lab, you have gained practical experience in installing Subversion (SVN) on Ubuntu 22.04, initializing a local SVN repository, and managing changes using core SVN commands such as commit, update, and revert. You learned to create a local SVN repository from scratch, commit new files to the repository, update your local copy to stay synchronized, and revert changes when needed. These are essential skills for effective version control and collaborative development using Subversion, empowering you in your role as a systemadmin or developer. You are now better equipped to manage code and configurations effectively.

400+ Linux Commands