Lab: Installing the OpenShift CLI (oc) on Ubuntu Linux
Lab Goal
In this lab, you will install the OpenShift command-line interface (oc) on an Ubuntu system and verify that it can successfully connect to an OpenShift cluster.
By the end, you will be able to:
- Download the correct
ocbinary - Install it system-wide
- Authenticate to an OpenShift cluster
- Run basic cluster commands
Prerequisites
- Ubuntu 20.04+ (works the same on 22.04 / 24.04)
- Internet access
- User account with
sudoprivileges - Access to an OpenShift cluster (ROSA, OpenShift Dedicated, self-managed, etc.)
Step 1: Verify Your System Architecture
Before downloading, confirm your CPU architecture:
uname -mExpected output for most systems:
x86_64If you see:
x86_64→ use linux-amd64aarch64/arm64→ use linux-arm64
Step 2: Download the OpenShift CLI
Option A: Download from Red Hat (recommended)
Go to:
https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz
From the command line:
cd /tmp
curl -LO https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gzStep 3: Extract the Archive
tar -xvf openshift-client-linux.tar.gzThis extracts:
ockubectl(OpenShift-compatible version)
Step 4: Install oc System-Wide
Move the binaries into /usr/local/bin:
sudo mv oc kubectl /usr/local/bin/Verify they’re executable:
oc versionExpected output (example):
Client Version: 4.x.x
Kubernetes Version: v1.xx.xAt this point, oc is successfully installed.
Step 5: Log In to an OpenShift Cluster
Login via Web Console
- Open your OpenShift web console
- Click your username (top right)
- Select Copy login command
- Choose Display Token
- Copy the
oc logincommand
Example:
oc login https://api.cluster.example.com:6443 \
--token=sha256~xxxxxxxxxxxxxxxxPaste and run it in your terminal.
Verify Login
oc whoamiExpected output:
your-usernameCheck cluster access:
oc get nodesStep 6: Basic oc Commands (Quick Tour)
oc status
oc get projects
oc get pods -A
oc explain podThese commands confirm:
- Authentication works
- API access is functional
- RBAC is enforced
Key Takeaways
ocis the primary interface to OpenShift- Installation is a simple binary download
ocextendskubectlwith OpenShift features- Once installed, the workflow is consistent across clusters
