Step by Step guide for the installation and configuration of Oracle Cloud Infrastructure (known as OCI) CLI (Command Line Interface) in Windows WSL2
Oracle Cloud Infrastructure is a next-generation enterprise-class
Cloud Provider. Oracle Cloud provides both new infrastructure and a full set of platform capabilities. Oracle Cloud is expanding its presence in more than 36 regional locations across the globe.
OCI and its resources can be accessed through multiple
methods like Cloud Console or Command Line Interface (CLI). OCI CLI provides the same functionalities as Cloud console with additional parameters and it also helps to execute scripts. CLI is built on OCI SDK for Python and runs on Mac, Windows or Linux.
As per Microsoft's documentation, " The Windows Subsystem for Linux lets developers run a GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a traditional virtual machine or dualboot setup."
Pre-requisite
Checking Windows version
Type Windows Logo Key + R and type Winver and select OK
Installation
Run Powershell as Administrator
At the Window Powershell prompt type:
wsl --install
And wait for the process to complete. For WSL to be properly activated, you will now need to restart your computer.
Now check available Linux distros:
wsl --list --online
Now you need to select the distros and execute this command
wsl --install -d <distros_name>
Once installation of Linux Distros is done, it will prompt for User. You
will need to create a user account and password for your newly installed Linux distribution.
Commonly Used WSL Commands
Listing of installed Linux distributions and check the version of WSL.
wsl -l -v
List of available Linux distributions available.
wsl -l -o
Name of the distribution you would like to install.
wsl --install -d <distros_name>
Update Package index inside WSL:
$ sudo apt update
$ sudo apt -y update
$ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
$ wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz
Extract the .tgz file
$tar -xf Python-3.8.3.tgz
You need to perform tests and optimizations before installing Python. It
increases the performance of the execution of codes by 10-20 percent:
$ cd Python-3.8.3
$ ./configure --enable-optimizations
Creating Virtual Environment for Python workspace
Creating a new folder for workspace (as Virtual Environment)
$ mkdir -p ~/OCI/python && cd ~/OCI/python
Create the virtual environment by running one of the following commands, depending on the version of Python installed:
$ python3.8 -m venv oracle-cli
After venv in place, it need to be activited. It is a crucial step.
$ source oracle-cli/bin/activate
Now download the OCI-CLI from OCI CLI release github
Download the Vanila release not the distribution specific one e.g. oci-cli-release.zip
$ curl -L "https://github.com/oracle/oci-cli/releases/download/v3.0.2/oci-cli-3.0.2.zip" -o /tmp/oci-cli-3.0.2.zip
Installing OCI using pip Python Package manager
bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"
It will prompt for the following options
===> Enter a path to an rc file to update (file will be created if it does not exist) (leave blank to use '/home/skdan/.bashrc'):
-- Backed up '/home/skdan/.bashrc' to '/home/skdan/.bashrc.backup'
-- Tab completion set up complete.
-- If tab completion is not activated, verify that '/home/skdan/.bashrc' is sourced by your shell.
--
-- ** Run `exec -l $SHELL` to restart your shell. **
--
-- Installation successful.
-- Run the CLI with /home/skdan/bin/oci –help
Post Installation, execute this command to verify the version
$/home/skdan/bin/oci -v