How to use Perforce on Linux
As I prefer to use Debian (and/or Ubuntu), and as Perforce only distributes Ubuntu .deb
packages,
this documentation relates to installing p4 on Ubuntu.
Contents:
- Installing p4 on Ubuntu Linux
- Upgrading p4 on Ubuntu Linux
- How to p4 sync a stream (
git clone
equivalent) - See Also
NOTE: If you’re trying to install a p4d
server, see the
Xist.GG Docker: Perforce Server for Unreal Engine
repository, which contains complete setup info for an Ubuntu server.
The commands described below only consider installing the p4
client.
Installing p4 on Ubuntu Linux
To install p4
(command-line utilities) on Ubuntu:
# Get OS package info (works on Ubuntu and Debian)
# Extract the "VERSION_CODENAME=bookworm"
source /etc/os-release
[ "x$VERSION_CODENAME" = "x" ] && echo "ERROR: OS INFO UNKNOWN" 1>&2
# Download and save the current version of the Perforce public key to local keyring
wget -qO - https://package.perforce.com/perforce.pubkey \
| sudo gpg --dearmor -o /usr/share/keyrings/perforce.gpg
# Add official perforce package source to local sources list
echo "deb [signed-by=/usr/share/keyrings/perforce.gpg] https://package.perforce.com/apt/ubuntu $VERSION_CODENAME release" \
| sudo tee /etc/apt/sources.list.d/perforce.list > /dev/null
# Update sources
sudo apt-get -y update
# CHECK FOR ERRORS HERE
# Install "helix-cli" package (p4 client tools)
sudo apt-get -y install helix-cli
Error Checking on apt-get -y update
Note that NOT ALL distributions are supported by Perforce.
If you see errors like this in your apt-get -y update
output,
it means that Perforce does not have a binary distribution for your
OS distribution:
E: The repository 'https://package.perforce.com/apt/ubuntu bookworm Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
In this case, your $VERSION_CODENAME
refers to an unsupported release.
What you need to do is try to install a package for a different distribution, preferably the most recent one for your OS that is actually supported.
For more information see Perforce Packages and the official list of supported OS Distributions.
In my case as of March 2025, debian
bookworm
is not supported,
so I instead installed debian
jammy
which is a recent, compatible distribution.
Recovering from an Error
sudo rm -f /etc/apt/sources.list.d/perforce.list
# Set this to whatever OS distro you explicitly want to use
VERSION_CODENAME=jammy
echo "deb [signed-by=/usr/share/keyrings/perforce.gpg] https://package.perforce.com/apt/ubuntu $VERSION_CODENAME release" \
| sudo tee /etc/apt/sources.list.d/perforce.list > /dev/null
sudo apt-get -y update
sudo apt-get -y install helix-cli
Upgrading p4 on Ubuntu Linux
At any point in the future, you can update p4
by running these commands:
# Update package versions
sudo apt-get -y update
# Upgrade helix-cli and its dependencies
sudo apt-get -y install helix-cli
How to fix expired Perforce Packaging key
The Perforce packaging key (/usr/share/keyrings/perforce.gpg
)
expired on August 14, 2023 UTC.
It will expire again on June 11, 2026 UTC.
Whenever it expires, you need to get the new version of the key from Perforce, then update your package sources.
# Download and save the current version of the Perforce public key to local keyring
wget -qO - https://package.perforce.com/perforce.pubkey \
| sudo gpg --dearmor -o /usr/share/keyrings/perforce.gpg
# Update package versions
sudo apt-get -y update
After running the above commands, you should once again be able to upgrade the helix-cli
package.
How to p4 sync a stream (git clone
equivalent)
So you are ready to start working on your team’s p4 stream! Very exciting.
Set up your p4 environment variables
I recommend doing this in your ~/.bash_profile
so it happens automatically every time you start a shell.
# configure this to be your team's p4d server (ask your lead)
export P4PORT="p4.your-company.com:1666"
# set this to your p4 username (we default to your Linux username)
export P4USER=`whoami`
# Name this based on your team's naming conventions
# At Xist.GG we use "project_user" with an optional "_host" at the end
export P4CLIENT="MyProject_$P4USER"
Create an new project workspace
You need to have your p4 environment set up to do this.
# Set this to whatever stream you want to work on (ask your lead)
MY_P4_STREAM="//My/Stream"
# Use whatever directory you prefer on your local workstation
MY_WORKSPACE_DIR="$HOME/dev/MyProject"
# Create the directory
mkdir -p $MY_WORKSPACE_DIR
# Login to the p4 server
p4 login
# Create a workspace on the server mapping to this directory
p4 client -i <<__EOF
Client: $P4CLIENT
Root: $MY_WORKSPACE_DIR
Stream: $MY_P4_STREAM
Owner: $P4USER
Host: `hostname`
__EOF
Sync the stream from the p4 server
You need to have your p4 environment set up to do this.
# cd to your workspace dir and sync files
cd $MY_WORKSPACE_DIR
p4 sync ... | tee .p4sync.txt
Once you start the p4 sync ...
it might consume your network for a while, you’re now downloading the entire stream.
Leave that terminal alone until it finishes syncing.
See Also
- Perforce Packages
- Especially useful if you use an
.rpm
based package manager
- Especially useful if you use an