Install the Oracle Cloud Infrastructure CLI on Ubuntu 20.04 LTS

This is a short post on how to install/configure the Oracle Cloud Infrastructure (OCI) Command Line Interface (CLI) on Ubuntu 20.04 LTS.

UPDATE 220221: Ubuntu 20.04 LTS is going out of support very soon – you should really use a different LTS release instead of this one! The steps presented in this article should apply to Ubuntu 22.04 LTS and 24.04 LTS, too. They haven’t been validated though, please use care.

On a couple of my machines I noticed the default Python3 interpreter to be 3.8.x, so I’ll stick with this version. I used the Manual installation, users with higher security requirements might want to consider the offline installation. If you want an all-in-one command, please refer to the documentation. I prefer more control over the things that happen on my systems, and I’m not a great fan of piping curl’d scripts into bash.

Creating a virtual environment

The first step is to create a virtual environment to prevent the OCI CLI’s dependencies from messing up my python installation.

martin@ubuntu:~$ mkdir -p ~/development/python && cd ~/development/python
martin@ubuntu:~/development/python$ python3 -m venv oracle-cli

If this command throws an error you may have to install the venv module via sudo apt install python3-venv

With the venv in place you need to activate it. This is a crucial step! Don’t forget to run it

martin@ubuntu:~/development/python$ source oracle-cli/bin/activate
(oracle-cli) martin@ubuntu:~/development/python$

As soon as the venv is activated you’ll notice its name – oracle-cli, has been added to the prompt.

Downloading the OCI CLI

The next step is to download the latest OCI CLI release from Github. At the time of this update, version 3.51.8 was the most current. Ensure you load the vanilla release, eg oci-cli-release.zip, not one of the distribution specific ones. They are to be used with the offline installation.

(oracle-cli) martin@ubuntu:~/development/python$ curl -Lo /tmp/oci-cli-3.51.8.zip \
> https://github.com/oracle/oci-cli/releases/download/v3.51.8/oci-cli-3.51.8.zip
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 139M 100 139M 0 0 15.2M 0 0:00:09 0:00:09 --:--:-- 14.2M

This downloads the ZIP file to /tmp in preparation of the installation.

Unzip the release in a temporary location and begin the installation by invoking pip using the “whl” file in the freshly unzipped directory. Just to make sure I always double-check I’m using the pip executable in the virtual environment before proceeding.

(oracle-cli) martin@ubuntu:~/development/python$ (cd /tmp && unzip -q oci-cli-3.51.8.zip)
(oracle-cli) martin@ubuntu:~/development/python$ which pip
/home/martin/development/python/oracle-cli/bin/pip
(oracle-cli) martin@ubuntu:~/development/python$ pip install /tmp/oci-cli/oci_cli-3.51.8-py3-none-any.whl
Processing /tmp/oci-cli/oci_cli-3.51.8-py3-none-any.whl
Collecting jmespath==0.10.0
Downloading jmespath-0.10.0-py2.py3-none-any.whl (24 kB)
Collecting PyYAML<=6.0.1,>=5.4
Downloading PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (736 kB)
|████████████████████████████████| 736 kB 6.0 MB/s
Collecting click==8.0.4
Downloading click-8.0.4-py3-none-any.whl (97 kB)
|████████████████████████████████| 97 kB 25.9 MB/s
Collecting terminaltables==3.1.10
Downloading terminaltables-3.1.10-py2.py3-none-any.whl (15 kB)
Collecting pyOpenSSL<25.0.0,>=17.5.0
Downloading pyOpenSSL-24.3.0-py3-none-any.whl (56 kB)
|████████████████████████████████| 56 kB 15.6 MB/s
Collecting prompt-toolkit<=3.0.43,>=3.0.38; python_version > "3.6"
Downloading prompt_toolkit-3.0.43-py3-none-any.whl (386 kB)
|████████████████████████████████| 386 kB 22.2 MB/s
Collecting oci==2.145.0
Downloading oci-2.145.0-py3-none-any.whl (29.1 MB)
|████████████████████████████████| 29.1 MB 852 kB/s
Collecting certifi
Downloading certifi-2025.1.31-py3-none-any.whl (166 kB)
|████████████████████████████████| 166 kB 32.6 MB/s
Collecting six>=1.15.0
Downloading six-1.17.0-py2.py3-none-any.whl (11 kB)
Collecting python-dateutil<3.0.0,>=2.5.3
Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)
|████████████████████████████████| 229 kB 27.1 MB/s
Collecting cryptography<46.0.0,>=3.2.1
Downloading cryptography-44.0.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB)
|████████████████████████████████| 4.2 MB 26.5 MB/s
Collecting pytz>=2016.10
Downloading pytz-2025.1-py2.py3-none-any.whl (507 kB)
|████████████████████████████████| 507 kB 24.3 MB/s
Collecting arrow>=1.0.0
Downloading arrow-1.3.0-py3-none-any.whl (66 kB)
|████████████████████████████████| 66 kB 21.8 MB/s
Collecting wcwidth
Downloading wcwidth-0.2.13-py2.py3-none-any.whl (34 kB)
Collecting circuitbreaker<3.0.0,>=1.3.1; python_version >= "3.7"
Downloading circuitbreaker-2.0.0-py2.py3-none-any.whl (7.6 kB)
Collecting cffi>=1.12; platform_python_implementation != "PyPy"
Downloading cffi-1.17.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (446 kB)
|████████████████████████████████| 446 kB 31.4 MB/s
Collecting types-python-dateutil>=2.8.10
Downloading types_python_dateutil-2.9.0.20241206-py3-none-any.whl (14 kB)
Collecting pycparser
Downloading pycparser-2.22-py3-none-any.whl (117 kB)
|████████████████████████████████| 117 kB 22.2 MB/s
Installing collected packages: jmespath, PyYAML, click, terminaltables, pycparser, cffi, cryptography, pyOpenSSL, wcwidth, prompt-toolkit, circuitbreaker, certifi, six, python-dateutil, pytz, oci, types-python-dateutil, arrow, oci-cli
Successfully installed PyYAML-6.0.1 arrow-1.3.0 certifi-2025.1.31 cffi-1.17.1 circuitbreaker-2.0.0 click-8.0.4 cryptography-44.0.1 jmespath-0.10.0 oci-2.145.0 oci-cli-3.51.8 prompt-toolkit-3.0.43 pyOpenSSL-24.3.0 pycparser-2.22 python-dateutil-2.9.0.post0 pytz-2025.1 six-1.17.0 terminaltables-3.1.10 types-python-dateutil-2.9.0.20241206 wcwidth-0.2.13

You’ll notice additional packages are pulled into the virtual environment by the setup routine. As always, exercise care when using external packages. An offline installation is available as well if your security requirements mandate it.

At the end of the process you have a working installation of the command line interface.

Configuration

Before you can use the CLI you need to provide a configuration file. The default location is ~/.oci, which I’ll use as well.

(oracle-cli) [martin@ubuntu python]$ mkdir ~/.oci && cd ~/.oci

Inside of this directory you need to create a config file and you need an API key, too. Have a look at the documentation for details. A word of warning: it’s strongly discouraged to store a potential passphrase (used for the API key) in the configuration file!

Happy Automation!