Setting Up OCI CLI and Creating a VM.Standard.A1.Flex Instance (Always Free eligible)
We used AI while writing this content.
Supported Platforms
| Platform | Support |
|---|---|
| Linux | ✅ |
| macOS | ✅ |
| Windows | ✅ |
Oracle Cloud Infrastructure (OCI)?
Oracle Cloud Infrastructure offers a generous Always Free tier globally that includes high-powered ARM-based compute instances. Each tenancy gets 4 OCPUs and 24 GB of memory for free using the VM.Standard.A1.Flex shape (equivalent to 3,000 OCPU hours and 18,000 GB hours per month).
However, due to high demand, you'll often encounter an "Out of Capacity" error when trying to create instances through the web console. This guide shows you how to use the OCI CLI to automate instance creation and bypass capacity issues.
Prerequisites
Before you begin, you need:
- An Oracle Cloud account (sign up at oracle.com/cloud/free)
- A Debian-based Linux system (Ubuntu, Debian, etc.)
- Python 3.6 or later
- Basic command-line knowledge
Setup
1. Install OCI CLI on Debian-based Linux
The OCI CLI installer automatically installs the CLI along with its dependencies (Python and virtualenv).
Open a terminal and run the installer script:
bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"
Note: For a silent install that accepts all defaults without prompts, add the
--accept-all-defaultsflag:bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)" -- --accept-all-defaults
The installer will:
- Install Python if not already present
- Create a virtual environment
- Install the OCI CLI and dependencies
- Optionally update your PATH
Verify the installation:
oci --version
If the command is not found, you may need to add it to your PATH or create an alias:
# Add to ~/.bashrc or ~/.bash_profile
export PATH=$PATH:~/bin
# or create an alias
alias oci='~/bin/oci'
2. Configure OCI CLI
Run the configuration setup dialog:
oci setup config
The setup wizard will prompt you for:
- Config file location: Default is
~/.oci/config - User OCID: Your user identifier
- Tenancy OCID: Your tenancy identifier
- Region: Your home region (e.g.,
us-ashburn-1,eu-frankfurt-1) - SSH key: The wizard will generate an API signing key pair
Finding Your OCIDs
- Log in to the OCI Console
- Click your profile icon (top right) → User Settings
- Copy your User OCID (starts with
ocid1.user.oc1..) - For Tenancy OCID: Profile icon → Tenancy → Copy the OCID
Upload Your API Public Key
After running oci setup config, you need to upload the generated public key:
- In the OCI Console, go to Profile → User Settings
- Under Resources (left sidebar), click API Keys
- Click Add API Key
- Select Paste Public Key
- Paste the contents of
~/.oci/oci_api_key_public.pem - Click Add
Verify Configuration
Test your configuration:
oci iam user get --user-id <your-user-ocid>
If successful, you'll see your user details in JSON format.
3. Set File Permissions
Ensure your private key has the correct permissions:
oci setup repair-file-permissions --file ~/.oci/oci_api_key.pem
Creating a VM.Standard.A1.Flex Instance
1. Gather Required Information
Before launching an instance, you need several identifiers. Let's collect them step by step.
Set Your Compartment ID
Most OCI commands require a compartment ID. Use your tenancy OCID (from your config file):
export C=$(grep tenancy ~/.oci/config | cut -d'=' -f2)
# or manually:
export C=ocid1.tenancy.oc1..aaaaaaaakpx***mpa
Get Availability Domain
List available domains:
oci iam availability-domain list --all --compartment-id=$C
Look for the "id" field in the output. Save it:
export AD=ocid1.availabilitydomain.oc1..aaaaaaaalcd***m2q
Verify the Shape
Confirm that VM.Standard.A1.Flex is available:
oci compute shape list --compartment-id=$C | grep "VM.Standard.A1.Flex"
Get Subnet ID
List your subnets:
oci network subnet list --compartment-id=$C
Save the subnet "id":
export S=ocid1.subnet.oc1.eu-frankfurt-1.aaaaaaaaahbb***faq
Get Image ID
List available ARM-compatible images for the A1 shape:
oci compute image list --compartment-id=$C --shape=VM.Standard.A1.Flex
Choose an image (e.g., Ubuntu) and save its "id":
export I=ocid1.image.oc1.eu-frankfurt-1.aaaaaaaa***ywv6wa
2. Launch the Instance
Now you have all the required information. Create the instance:
oci compute instance launch \
--compartment-id $C \
--availability-domain $AD \
--shape VM.Standard.A1.Flex \
--shape-config '{"ocpus":4.0,"memoryInGBs":24}' \
--display-name "my-a1-instance" \
--image-id $I \
--subnet-id $S \
--assign-public-ip true \
--instance-options file://~/Syncthing/oci/instanceOptions.json \
--ssh-authorized-keys-file ~/.ssh/id_rsa.pub
Verify the latest Oracle API references if you are getting a 400 bad request error. Oracle people change their APIs WAY TOO OFTEN ...
3. Handle "Out of Capacity" Errors
You are more likely to receive the "Out of Capacity" warning while on the Always Free plan, as Oracle prioritises Pay as You Go users.
If you receive an "Out of Capacity" error, Oracle may not have available resources at that moment. You can automate retry attempts with a simple loop:
#!/bin/bash
# Script to retry instance creation until successful
while true; do
oci compute instance launch \
--compartment-id $C \
--availability-domain $AD \
--shape VM.Standard.A1.Flex \
--shape-config '{"ocpus":4.0,"memoryInGBs":24}' \
--display-name "my-a1-instance" \
--image-id $I \
--subnet-id $S \
--assign-public-ip true \
--instance-options file://~/Syncthing/oci/instanceOptions.json \
--ssh-authorized-keys-file ~/.ssh/id_rsa.pub
# Check if successful
if [ $? -eq 0 ]; then
echo "Instance created successfully!"
break
fi
echo "Failed to create instance. Retrying in 60 seconds..."
sleep 60
done
Important: If you're on a "Pay as you go" plan, be careful with automated loops to avoid unintended charges. Always add a condition to stop after success.
4. Verify Instance Creation
List your instances:
oci compute instance list --compartment-id $C
Check the instance status and get its public IP address from the output.
5. Attach a Public IP (if needed)
If you didn't assign a public IP during creation, you can attach one later:
- Go to OCI Console → Compute → Instances
- Select your instance
- Click Attached VNICs under Resources
- Click the VNIC name
- Click IPv4 Addresses
- Click Assign Public IP Address
Managing Your Instance
Start an Instance
oci compute instance action --action START --instance-id <instance-ocid>
Stop an Instance
oci compute instance action --action STOP --instance-id <instance-ocid>
Terminate an Instance
oci compute instance terminate --instance-id <instance-ocid>
Troubleshooting
Command Not Found
If oci command is not found after installation:
# Find the installation directory
find ~ -name oci -type f 2>/dev/null
# Add to PATH or create alias
echo 'export PATH=$PATH:~/bin' >> ~/.bashrc
source ~/.bashrc
Authentication Errors
- Verify your config file:
cat ~/.oci/config - Ensure the private key path is correct
- Check API key is uploaded to OCI Console
- Verify file permissions:
ls -l ~/.oci/oci_api_key.pem(should be 600)
Capacity Issues
- Try different availability domains
- Try different regions
- Use the retry script above
- Be patient—Oracle adds capacity regularly
Member discussion