How to use p4 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 (here we print it out just so you can see it)
lsb_release -a
# Extract the "Codename: xxx" from the `lsb_release -a` output
# $DISTRO = Like "noble" or "bookworm", etc
DISTRO=`lsb_release -a | grep '^Codename' | sed -e 's,.*:[[:space:]]*,,'`
# 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 $DISTRO release" \
| sudo tee /etc/apt/sources.list.d/perforce.list > /dev/null
# Update sources
sudo apt-get -y update
You should see the perforce sources listed in the output, something like:
Get:1 https://package.perforce.com/apt/ubuntu noble InRelease [7646 B]
Get:2 https://package.perforce.com/apt/ubuntu noble/release amd64 Packages [9461 B]
... more output ...
Once your packages are configured correctly, you can install p4
:
# Install "helix-cli" package (p4 client tools)
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