Installing Perforce on Ubuntu 12.0.4 LTS

Ever since LabVIEW was introduced as the preferred programming language for FRC, every team I have ever mentored has struggled with managing code revisions across multiple computers and programmers. Situations like “the programmer is sick” or “my hard drive died” are much more common than what you’d think.

Unlike most text-based languages, LabVIEW manages code using binaries. Because of this, revision control systems such as Git and Google Code have issues working with LabVIEW. There are commercial solutions for LabVIEW version control, but very few offer the ability to create user accounts with specific privileges for each user and much less provide a free version for others to tinker with. I’ve chosen to use Perforce this season since they offer a free 20 user license and their server software can easily be deployed to a VPS or simple Ubuntu installation. I am basing my tutorial on a previous tutorial by David Medinets. I’ve added some corrections to a script and adjusted a couple steps to make sure that your installation goes smoothly.

In order to deploy a Perforce server on Ubuntu 12.0.4 LTS you will need:

  1. A VPS or some other PC connected to the internet or your local network. I’m using an inexpensive VPS from UGVPS. Speed, memory, bandwidth, and cost are reasonable.
  2. A copy of Ubuntu 12.0.4 LTS (x32 or x64)
  3. Perforce P4D Server for Linux (not Unix, x32 or x64)
  4. Perforce P4 Command Line Client for Linux (not Unix, x32 or x64)
  5. WinSCP to transfer files to your Ubuntu installation (alternatively you can use Lynx to download the necessary files directly to your server)

I will be performing the installation remotely onto a VPS using PuTTY. The client I will be using to test this installation will be installed on a PC running Windows 7 x64. This guide assumes that you have already set up SSH, UFW (Ubuntu Firewall) is disabled, and you have already updated your installation (apt-get upgrade & apt-get update).

I have chosen to give Perforce its own user account and group. This should help with security and make it easier to partition server roles should you choose to use the server for something else (OpenVPN maybe?).

Let’s get started! Once you’ve installed all the software required and downloaded the appropriate files, open up WinSCP and transfer over the “p4d” and “p4” files to your server. Place them in your home directory.

Now, let’s move the files over to the recommended installation directory, /usr/local/bin

sudo mv /home/YOURUSERACCOUNT/p4 /usr/local/bin/
sudo mv /home/YOURUSERACCOUNT/p4d /usr/local/bin/

Once there, let’s make the files executable.

cd /usr/local/bin/
sudo chmod +x p4 p4d

Now, let’s install the “daemon” utility which the control script will use to run Perforce as another user.

sudo apt-get install daemon

Next, let’s create a group and user account for Perforce

sudo addgroup p4admin
sudo adduser perforce

Afterwards, let’s add the “perforce” user account to the sudoers list using ‘visudo’

sudo visudo

Append the following to your file

#User privilege specification
perforce   ALL=(ALL:ALL) ALL

If you’re accessing your VPS remotely using PuTTY and your server is configured securely, you will need to add the “perforce” user account to your list of permitted login users

sudo nano /etc/ssh/sshd_config

Add the following to your file

AllowUsers perforce

Log off of your server and log in using your new perforce account

Next, let’s create a couple directories that Perforce will be using

sudo mkdir /var/log/perforce
sudo mkdir /perforce_depot
sudo chown perforce:p4admin /var/log/perforce
sudo chown perforce:p4admin /perforce_depot

Now, let’s add some configuration settings to the profile file in order to allow our local client to connect to the Perforce server

sudo nano /etc/profile

Add this to the end of the file

# Perforce Settings
export P4JOURNAL=/var/log/perforce/journal
export P4LOG=/var/log/perforce/p4err
export P4PORT=localhost:1666
export P4ROOT=/perforce_depot
export P4USER=perforce

Load the Perforce settings file

source /etc/profile

Open the init.d directory and create a new script

cd /etc/init.d/
sudo nano perforce

Paste the following script into the new file

 #!/bin/sh -e

  export P4JOURNAL=/var/log/perforce/journal
  export P4LOG=/var/log/perforce/p4err
  export P4ROOT=/perforce_depot
  export P4PORT=1666


  . /lib/lsb/init-functions

  p4start="p4d -d"
  p4stop="p4 admin stop"

  case "$1" in
    log_action_begin_msg "Starting Perforce Server"
    daemon --user=$p4user $p4start;

    log_action_begin_msg "Stopping Perforce Server"
    daemon --user=$p4user $p4stop;


    echo "Usage: /etc/init.d/perforce (start|stop|restart)"
    exit 1


exit 0

Make the script executable

sudo chmod +x /etc/init.d/perforce

Add the script to the startup routine

sudo update-rc.d perforce defaults

Manually start the server. I prefer to do this manually the first time in order to make sure everything starts up correctly

cd ~
sudo p4d -d

Create the Perforce journal

sudo p4d -jc

Verify that the script works by restarting the server

sudo /etc/init.d/perforce restart

That’s it! Go ahead and try connecting to your server on a windows client! You should be greeted with this screen:

Your screen might not have any Depots or Workspaces, but you should now be connected! The default user should be “perforce” and the password should be whatever you set your Ubuntu account password to be.

I recommend creating your own user account and giving that account SU privileges within the Perforce login screen. If you prefer to manually add accounts and privileges, you can use the following command.

sudo p4 protect

Finally, let’s add an exception to UFW and enable it

sudo ufw allow 1666
sudo ufw enable
sudo ufw status

I hope this helps out someone! If this got you through your installation, please let me know in the comments below!