Skip to content

oci

Quickly install and configure the OCI CLI

Learn how to install and configure the Oracle Cloud Infrastructure (OCI) CLI. This guide provides simple instructions for getting started with the OCI command-line tool.

Introduction

The OCI CLI is a Python-based command-line interface that allows developers and system administrators to interact with OCI services. It enables automation and scripting for various cloud operations, enhancing efficiency.

Install the CLI

There are several ways to install the OCI CLI depending on your operating system and preference. Choose the method that best suits your needs.

This method is recommended for Linux and macOS users as it leverages the pip package manager, making updates easier.

sh
pip install oci-cli

Using Homebrew (macOS)

If you use Homebrew package manager on macOS, you can install the OCI CLI with a single command.

sh
brew install oci-cli

Using a script (Linux)

For Linux users who don't prefer using pip, you can install the OCI CLI using a script provided by Oracle.

sh
bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"

This command uses curl to download the installation script from GitHub and then executes it using bash.

Using a script (Windows)

For Windows, you'll need to download the installer directly from GitHub.

  1. Click the provided link: https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.ps1
  2. This link points to a script that downloads and installs the OCI CLI for Windows.
  3. Important: Download the script and run it using PowerShell with administrator privileges.

Setup the configuration file

After installing the OCI CLI, you need to configure it to access your OCI resources. This involves creating API keys and setting up a configuration file.

Create API keys

  1. Open a terminal window.
  2. Run the following command:
sh
oci setup keys

This command will guide you through an interactive process to create an API key pair. You'll be prompted to enter a descriptive name for your key pair and choose the fingerprint of the key you want to associate. Finally, it will download two files:

  • oci_api_key.pem: This is your private key file. Keep this file secure as it grants access to your OCI resources.
  • oci_api_key_public.pem: This is your public key file. You'll need to upload this to the OCI console.

Upload the public key

  1. Go to the OCI console at https://cloud.oracle.com/ and sign in to your account.
  2. Click on your user icon in the top right corner and select "User settings".
  3. In "User settings", navigate to "API keys" under "Resources".
  4. Click on "Add API key".
  5. Choose "Paste a public key". Open the oci_api_key_public.pem file, copy its entire content (including the header and footer lines), and paste it into the provided field.
  6. Click "Add".

Save the configuration file

The OCI console will display a configuration file snippet containing essential information for configuring the OCI CLI.

  1. Open a text editor (e.g., vi, nano) on your system.
  2. Create a new file named config (or any desired name) in the appropriate location.

    NOTE

    For best practices, consider creating a hidden directory (starting with a dot ".") in your home directory to store the configuration file (e.g., ~/.oci/config).

  3. Paste the copied configuration snippet from the OCI console into the config file.
  4. Edit the key_file line in the configuration file to point to the actual location of your private key file (oci_api_key.pem).
  5. Security: On Linux and macOS, set restrictive permissions for the config file to prevent unauthorized access. Run the following command, replacing path/to/config with the actual path to your configuration file:
    sh
    chmod 600 path/to/config
    This command sets the file permissions to allow only the owner (you) read and write access.