Install Oracle OCI CLI on Linux machine or container

Feb 8, 2024, by Rovshan Mirza

If you use Oracle Cloud on regular basis and you want to automate some mundane and repetitive tasks, or even manage it from terminal, then you have to install OCI CLI tool. OCI stands for Oracle Cloud Infrastructure. It's a CLI for managing Oracle Cloud and it can be installed on Linux, Mac and Windows.

In this post I'm going to show you how to install it on Linux LXC container, which I created in my Proxmox server. You can use any Linux machine for this as long as it's outside of Oracle Cloud and it has internet access.

1. Update Linux and install curl, python

After creating a brand new Ubuntu LXC container, I need to update the package index files and install curl and python.

apt update && apt upgrade -y
apt install curl -y
apt install python3-pip -y

2. Install OCI CLI

  1. Install OCI CLI by running below script. Press Enter to accept default settings.
bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)" --accept-all-defaults
  1. Reboot or just restart .bashrc.
. ~/.bashrc
  1. Verify installation.
oci --version

3. Setup OCI Configuration File

  1. Get User and Tenancy OCID from Oracle Cloud.
    1. Login to https://cloud.oracle.com.
    2. Go to Indentity & Security > Users.
    3. Click on oracleidentitycloudservice user.
    4. Take note of user OCID under User information.
    5. Go to Governance & Administration > Tenancy details.
    6. Take note of tenancy OCID under Tenancy information.
  2. Run below command to configure OCI CLI.
oci setup config
  • Enter a location for your config [/root/.oci/config]: Enter
  • Enter a user OCID: User OCID
  • Enter a tenancy OCID: Tenancy OCID
  • Enter a region by index or name: Enter name or index of the region where your instance is located, e.g. us-ashburn-1
  • Do you want to generate API RSA key pair: Y
  • Enter a directory for the keys: Enter
  • Enter a name for the key: Enter
  • Enter a passphrase: "N/A" for no passphrase
    • Don't provide passphrase if you want to run OCI commands automatically on schedule
  1. Run below command to verify the config flle.
cat /root/.oci/config

5. Upload OCI Public Key

  1. Display the public key and copy it.
cat /root/.oci/oci_api_key_public.pem
  1. Login to https://cloud.oracle.com.
  2. Go to Identity & Security > Users.
  3. Click on API Keys under Resources.
  4. Add API Key.
  5. Select Paste Public Key and paste the public key
  6. Add & Close.

4. Test OCI CLI

  1. Get Instance OCID from Compute > Instance.
  2. Run below command to get instance information.
oci compute instance get --instance-id [Instance OCID]
  1. If it returns a json file with instance information, then OCI CLI is configured correctly.