This topic describes how to install Object Storage Service (OSS) SDK for Ruby.

Prerequisites

  • Alibaba Cloud OSS is activated.

    To activate OSS or obtain more information about OSS, go to the OSS product page.

  • An AccessKey pair is created.

    For more information about how to create an AccessKey pair for a Resource Access Management (RAM) user, see Create an AccessKey pair for a RAM user.

Install OSS SDK for Ruby

You can use one of the following methods to install OSS SDK for Ruby:

  • Method 1

    Run the gem install aliyun-sdk command to install OSS SDK for Ruby.

    Note If you cannot access https://rubygems.org, we recommend that you use the mirror that is maintained by Ruby China.
    gem install aliyun-sdk --clear-sources --source https://gems.ruby-china.com 
  • Method 2

    Use bundler to install OSS SDK for Ruby.

    1. Add gem 'aliyun-sdk', '~> 0.6.0' to the Gemfile file of your application.
    2. Use a mirror to install OSS SDK for Ruby.
      Note https://gems.ruby-china.com is a mirror of https://rubygems.org and is maintained by Ruby China. The mirror is automatically synchronized and updated. If you cannot access rubygems.org, you can use the mirror to install OSS SDK for Ruby.
      bundle config mirror.https://rubygems.org https://gems.ruby-china.com 
      bundle install                        

Dependencies

  • Ruby 1.9.3 or later is required.
  • A Linux, Windows, or macOS operating system is required.
Notice
  • Some dependency files are gem native extensions. Therefore, you must install Ruby Devkit to compile the files.
  • The nokogiri gem dependency that OSS SDK for Ruby uses to process XML files must include the zlib library.
In Linux, Windows, and macOS operating systems, perform the following steps to install the dependencies.
  • Linux

    Run the following command to install the preceding dependencies. In this example, the Ubuntu operating system is used, which is a Linux distribution.

    sudo apt-get install ruby ruby-dev zlib1g-dev
                            

    Each Linux distribution has its package manager. You can install a package manager in a similar way.

  • Windows
    1. Visit RubyInstaller to download an installer. Double-click to download an installer and select Add Ruby executables to your PATH to install the installer.
      Note Download Ruby 2.1 or earlier. Ruby 2.2 cannot be installed. For more information, visit GitHub.
    2. Visit RubyInstaller to download the corresponding development kit. Create a folder named RubyDev in the root directory of the C drive. Then, decompress the development kit to this folder.
    3. Press Windows + R and enter cmd. Then, press the Enter key. In the Command Prompt, enter the following command:
       cd C:\RubyDev
       ruby dk.rb init
       ruby dk.rb install                                

      If a config.yml configuration error occurs, we recommend that you open C:\RubyDev\config.yml by using the text editor and change the content to the following content:

       ---
       - C:/Ruby21
                                      

      Save the config.yml file. Then, run the ruby dk.rb install command to complete the installation. In the preceding example, Ruby21 indicates the installation directory of Ruby. You can specify your actual directory. After the development kit is installed, close the Command Prompt.

    4. Enter the gem install aliyun-sdk command.

      After OSS SDK for Ruby is installed, enter irb to open the interactive command-line prompt of Ruby. Enter require 'aliyun/oss' in the interactive command-line prompt. If true is displayed, OSS SDK for Ruby is installed.

  • macOS

    By default, the macOS operating system has Ruby installed. For your convenience, we recommend that you install another version of Ruby for your development.

    1. Enter xcode-select --install in Terminal to install Xcode Command Line Tools. If the tools fail to be installed, we recommend that you manually download the tools and install them.
      Note You can use your Apple ID to log on to Apple Developer and download Xcode Command Line Tools. Select your macOS version. After the tools are downloaded, double-click the dmg file. In the window that appears, double-click the installation program. During this process, you must enter your Apple password.
    2. Run the following command in Terminal to install brew:
       ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
                                      
    3. Run the following command in Terminal to install Ruby:
       brew install ruby
       exec $SHELL -l
                                      
    4. Run the following command in Terminal to install OSS SDK for Ruby:
       gem install aliyun-sdk
                                      
    5. Run the following command in Terminal to check whether OSS SDK for Ruby is installed. If true is displayed, OSS SDK for Ruby is installed.
       irb
       > require 'aliyun/oss'
       => true
                                      

References