Install the CLI

更新时间:
复制 MD 格式

The SLS CLI supports most SLS features, including project management, Logstore management, log queries, automatic paging, and cross-account geo-replication.

Before you start

The SLS CLI requires Python. Download it from the official Python website.

Item

Description

Current CLI version

0.2.9

Note

Run the install command to upgrade. Always use the latest version.

Source code

Aliyun Log CLI

Supported Python versions

  • Python 2: 2.7 or later

  • Python 3: 3.7 or later

Supported operating systems

Windows, Linux, and macOS.

Dependent components

After installing Python, install these dependencies with pip install package_name:

  • docopt

  • aliyun-log-python-sdk

  • jmespath

  • aliyun-python-sdk-core

  • aliyun-python-sdk-sts

  • requests

Step 1: Configure Python environment variables

Important

Configure environment variables so that the aliyunlog commands run correctly. After configuration, you may need to restart your IDEs or services for the changes to take effect.

Configure Python environment variables in Linux and macOS

  1. Create the .bash_profile file.

    Note

    If this is your first time setting environment variables, run touch ~/.bash_profile to create the file. If it already exists, run vim ~/.bash_profile to edit it.

    touch ~/.bash_profile
    vim ~/.bash_profile
  2. View the Python installation directory.

    which python3
  3. Configure the .bash_profile file.

    export PATH=$PATH:/usr/local/python3/bin
  4. Apply the settings in the .bash_profile file.

    # Make the configuration file take effect.
    source ~/.bash_profile

Configure Python environment variables in Windows

Set environment variables in the Windows 10 GUI:

  1. Find the Python installation path.

    On the desktop, right-click This PC and select Properties > Advanced System Settings > Environment Variables > User Variables > Path to find the environment variable for Python.

  2. Add the Python environment variable.

    On the desktop, right-click This PC, and select Properties > Advanced System Settings > Environment Variables > User Variables > Path > Create, for example, if the variable that you found in Step 1 is D:\dev\python\python37\, the variable that you need to add is D:\dev\python\python37\bin.

Step 2: Install the CLI

Install the CLI in Linux

  1. Log on to a Linux server.

  2. Install the CLI:

    pip3 install aliyun-log-python-sdk aliyun-log-cli -U --no-cache
  3. Verify the installation.

    Run the following command:

    aliyunlog --version

    A successful output confirms the installation.

Install the CLI in Windows

  1. Log on to a Windows server.

  2. Open a command prompt.

    If the Python environment variable is set, proceed to the next step. If pip3 is not found, navigate to the Python installation path with cd before running the install command.

  3. Install the CLI:

    pip3 install aliyun-log-python-sdk aliyun-log-cli -U --no-cache
  4. Verify the installation.

    Run the following command:

    aliyunlog --version

    A successful output confirms the installation.

Install the CLI in macOS

Install the SLS CLI with pip3:

pip3 install -U aliyun-log-cli --no-cache

Upgrade the CLI

Re-run the install command to upgrade to the latest version.

Uninstall the CLI

To uninstall the CLI:

pip3 uninstall aliyun-log-cli

FAQ

The default Python version on an ECS Linux instance is 3.6. How do I upgrade Python to 3.7 or later?

Do not uninstall the default Python on ECS. Instead, modify the symbolic link or use a multi-version management tool.

  • Modify the symbolic link

    1. Install a later Python version. Install Python using a package manager.

    2. Run which python3 to find the installation path, for example /usr/bin/python3.

    3. Modify the symbolic link.

      sudo which python3 pip3
      rm -rf /usr/bin/python3 /usr/bin/pip3
      
      # Add a symbolic link. /usr/bin/python3.11 is the installation path of the later version.
      sudo ln -s /usr/bin/python3.11 /usr/bin/python3
      sudo ln -s /usr/bin/pip3.11 /usr/bin/pip3
    4. Run python -V to verify the change.

  • Multi-version management tool