此内容没有您所选择的语言版本。

Chapter 2. Getting started with the OpenShift CLI


To use the OpenShift CLI (oc) tool, you must download and install it separately from your MicroShift installation. You can install oc by downloading the binary or by using Homebrew.

2.1. Installing the OpenShift CLI

You can install the OpenShift CLI (oc) to interact with Red Hat build of MicroShift from a command-line interface. You can install oc on Linux, Windows, or macOS.

Important

If you installed an earlier version of oc, you cannot use it to complete all of the commands in Red Hat build of MicroShift.

Download and install the new version of oc.

2.1.1. Installing the OpenShift CLI on Linux

You can install the OpenShift CLI (oc) binary on Linux by using the following procedure.

Note

Red Hat build of MicroShift version numbering matches OpenShift Container Platform version numbering. Use the oc binary that matches your MicroShift version and has the appropriate RHEL compatibility.

Procedure

  1. Navigate to the Download OpenShift Container Platform page on the Red Hat Customer Portal.
  2. Select the architecture from the Product Variant list.
  3. Select the appropriate version from the Version list.
  4. Click Download Now next to the OpenShift v4.20 Linux Clients entry and save the file.
  5. Unpack the archive:

    $ tar xvf <file>
    Copy to Clipboard Toggle word wrap
  6. Place the oc binary in a directory that is on your PATH.

    To check your PATH, execute the following command:

    $ echo $PATH
    Copy to Clipboard Toggle word wrap

Verification

  • After you install the OpenShift CLI, it is available using the oc command:

    $ oc <command>
    Copy to Clipboard Toggle word wrap

2.1.2. Installing the OpenShift CLI on Windows

You can install the OpenShift CLI (oc) binary on Windows by using the following procedure.

Note

Red Hat build of MicroShift version numbering matches OpenShift Container Platform version numbering. Use the oc binary that matches your MicroShift version and has the appropriate RHEL compatibility.

Procedure

  1. Navigate to the Download OpenShift Container Platform page on the Red Hat Customer Portal.
  2. Select the appropriate version from the Version list.
  3. Click Download Now next to the OpenShift v4.20 Windows Client entry and save the file.
  4. Unzip the archive with a ZIP program.
  5. Move the oc binary to a directory that is on your PATH.

    To check your PATH, open the command prompt and execute the following command:

    C:\> path
    Copy to Clipboard Toggle word wrap

Verification

  • After you install the OpenShift CLI, it is available using the oc command:

    C:\> oc <command>
    Copy to Clipboard Toggle word wrap

2.1.3. Installing the OpenShift CLI on macOS

You can install the OpenShift CLI (oc) binary on macOS by using the following procedure.

Note

Red Hat build of MicroShift version numbering matches OpenShift Container Platform version numbering. Use the oc binary that matches your MicroShift version and has the appropriate RHEL compatibility.

Procedure

  1. Navigate to the Download OpenShift Container Platform on the Red Hat Customer Portal.
  2. Select the appropriate version from the Version drop-down list.
  3. Click Download Now next to the OpenShift v4.20 macOS Clients entry and save the file.
  4. Unpack and unzip the archive.
  5. Move the oc binary to a directory on your PATH.

    To check your PATH, open a terminal and execute the following command:

    $ echo $PATH
    Copy to Clipboard Toggle word wrap

Verification

  • Verify your installation by using an oc command:

    $ oc <command>
    Copy to Clipboard Toggle word wrap

2.2. Installing the OpenShift CLI by using Homebrew

For macOS, you can install the OpenShift CLI (oc) by using the Homebrew package manager.

Prerequisites

  • You must have Homebrew (brew) installed.

Procedure

  • Install the openshift-cli package by running the following command:

    $ brew install openshift-cli
    Copy to Clipboard Toggle word wrap

Verification

  • Verify your installation by using an oc command:
$ oc <command>
Copy to Clipboard Toggle word wrap

2.3. Installing the OpenShift CLI by using an RPM

For Red Hat Enterprise Linux (RHEL), you can install the OpenShift CLI (oc) as an RPM if you have an active Red Hat build of MicroShift subscription on your Red Hat account.

Important

You must install oc for RHEL 9 by downloading the binary. Installing oc by using an RPM package is not supported on Red Hat Enterprise Linux (RHEL) 9.

Prerequisites

  • Must have root or sudo privileges.

Procedure

  1. Register with Red Hat Subscription Manager:

    # subscription-manager register
    Copy to Clipboard Toggle word wrap
  2. Pull the latest subscription data:

    # subscription-manager refresh
    Copy to Clipboard Toggle word wrap
  3. List the available subscriptions:

    # subscription-manager list --available --matches '*OpenShift*'
    Copy to Clipboard Toggle word wrap
  4. In the output for the previous command, find the pool ID for an Red Hat build of MicroShift subscription and attach the subscription to the registered system:

    # subscription-manager attach --pool=<pool_id>
    Copy to Clipboard Toggle word wrap
  5. Enable the repositories required by Red Hat build of MicroShift 4.20.

    # subscription-manager repos --enable="rhocp-4.20-for-rhel-8-x86_64-rpms"
    Copy to Clipboard Toggle word wrap
  6. Install the openshift-clients package:

    # yum install openshift-clients
    Copy to Clipboard Toggle word wrap

Verification

  • Verify your installation by using an oc command:
$ oc <command>
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat