All Products
Search
Document Center

Object Storage Service:Installation

Last Updated:Dec 12, 2023

OSS SDK for Ruby allows you to programmatically manage resources in Object Storage Service (OSS). For example, you can manage buckets, upload objects, download objects, and manage access permissions on objects. This topic describes how to use OSS SDK for Ruby.

Procedure

Linux

In the following example, Ubuntu 22.04 is used.

  1. Install Ruby by using apt-get.

    apt-get install -y ruby
  2. Specify the Alibaba Cloud RubyGems image as a new RubyGems source and delete the default RubyGems source.

    gem sources -a http://mirrors.aliyun.com/rubygems/ -r https://rubygems.org/
  3. Install dependencies.

    sudo apt-get install ruby ruby-dev zlib1g-dev
    Important
    • 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.

  4. Install OSS SDK for Ruby.

    Method 1: Run the gem command to install OSS SDK for Ruby

    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.

      bundle config mirror.https://rubygems.org https://gems.ruby-china.com 
      bundle install                        
      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.

Windows

  1. Go to the RubyInstaller site to download the Ruby+Devkit installation package. After the installation package is downloaded, double-click the package to install the package by using the installation wizard.

  2. 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

  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