Tutorial

Using GoodData Ruby SDK on Apple Sillicon

  • 28 March 2023
  • 0 replies
  • 112 views

  • Anonymous
  • 0 replies

The following article describes the procedure on how to set up the environment to use the GoodData Ruby SDK. It is focused on machines using ARM64 chips (M1 Macs, also known as Apple Sillicon). The installation can be cumbersome and not really straightforward. The procedure was tested on MacBook PRO with M1 chip and MacOS Ventura 13.2 as an operating system. 

The Goodata Ruby Gem is supported and tested only on these Ruby versions:

  • 2.2
  • 2.3
  • 2.4
  • 2.5
  • 2.6
  • jruby-1.7.19
  • jruby-9.1.5
  • jruby-9.1.7
  • jruby-9.1.14

We will show you how to install Ruby version 2.6.8 and Gooddata Gem. To do this we have chosen to use rbenv as a Ruby version management tool. The simplest way to manage programs designed for Linux machines (including rbenv) is to install HomeBrew. 

There are two general approaches to achieve this. The simpler utilizes the proprietary Rosetta 2 technology that allows you to run programs designed for x64 architecture natively. This, however, results in slightly slower performance. The latter approach forces installation of older Ruby versions directly. Although lengthier and slightly more complex, you will gain improved performance and less memory utilization when using Ruby 2.#.

Both recommended approaches leverage the quintessential HomeBrew program.

Forced installation

If you have HomeBrew already on your machine, you can skip this step and move forward to rbenv installation. Otherwise, you have to run following command to install it:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

After running this command, you will be probably asked for an account password. The installation procedure can take a while. After it finishes, you have to run the following commands in order to be able to run brew commands without a path to the installation folder. Replace {username} with your OS user name.

echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/{username}/.zprofile

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/{username}/.zprofile

eval "$(/opt/homebrew/bin/brew shellenv)"

Test your installation with brew -v. The result should look like this (the version can differ):

Homebrew 3.6.20

Homebrew/homebrew-core (git revision 2f7330fe49b; last commit 2023-01-26)

Forced installation

RBENV Installation

The next step is to install rbenv which is a version management tool for Ruby. Its function is akin to pyenv for Python. It allows you to use multiple versions of Ruby in one machine and ensures that each project/folder will run with the desired version. 

https://github.com/rbenv/rbenv

To install rbenv on your machine, run following commands in your terminal one by one:

brew install rbenv ruby-build

rbenv init

echo 'eval "$(rbenv init -)"' >> ~/.zshrc

export PATH="$HOME/.rbenv/shims:$PATH"

The first command will simply install rbenv using HomeBrew. The second will initialize rbenv in your current terminal instance. If you do not want to run this command every time you restart or reopen your terminal, you should execute the third command. The zshrc file is used to set up your shell environment whenever you open a new terminal or simply new shell instance. Finally you have to run the last command to add a shims path to your PATH environment variable. The shim provided by rbenv is intercepting ruby commands in order to provide the desired environment/version.  

Ruby Installation & Version Management

After that you can install the desired Ruby version by running:

RUBY_CFLAGS="-w" rbenv install 2.6.8

If you run it without the RUBY_CFLAGS argument, it will most probably not work. It will simply ignore some non related errors. Now you have the Ruby version 2.6.8 installed and you can see it by entering this command:

rbenv versions

This will display all the installed versions including the system one. You can see it in the following example.

* system (set by /Users/admin/.rbenv/version)

  2.6.8

The asterisk is telling you which version is currently active. To select the 2.6.8 version you have two options. Either you want to use the version globally for every project or you can use it locally just for one. This is the advantage of rbenv, so you can use different versions among all of your projects. For global usage run:

rbenv global 2.6.8

And to use it locally you have to go to the folder where your project sits and type:

rbenv local 2.6.8

This will create a .ruby-version file in your project folder and it simply tells the system to use the version written in the file.

Now you can verify which version is in use by executing the following:

ruby -v

Installing Gooddata Gem

You are now free to install the Gooddata Gem by entering this command:

gem install gooddata --user-install

Before executing your first script you should restart your shell. After that you are ready to explore Gooddata Platform using the Ruby SDK. 

Rosetta 2

Disclaimer: The following guide was tested on macOS Ventura. Any future updates to your operating system may render this guide obsolete.

Installing Rosetta 2

As mentioned in the preface, Rosetta is a proprietary technology from Apple to allow backwards compatibility with older programs.

If you have never used any older version of programs designed to run on x64 architecture (Intel chips in the case of Macbooks), you will most likely not have Rosetta installed. Getting it on your machine is quite straightforward. Open your Terminal and execute the following command:

softwareupdate --install-rosetta

You will be prompted to read and agree with EULA. After agreeing, your Mac will automatically install the latest version of Rosetta.

Whenever you wish to run a command in your Terminal under backward compatibility mode, you can do so by specifying the desired architecture with arch command:

arch -x86_64 ${your_command}

Running arch command without any parameters will print your machine’s actual architecture into the standard output.

You can find more information about Rosetta and its limitations at the official Apple Developer page: https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment.

Ruby Versioning Managers

We do not want to touch, alter or use the system’s native Ruby (that every current Mac is shipped with) for any purpose, as the operating system uses it to run various system-level tasks. Making changes to it could very well break your system. To handle this, we will need a Ruby versioning manager tool. There are various and thus we will cover rbenv.

RBENV

If you decide to utilize rbenv, you will need to follow these steps to ensure it works properly and can be leveraged to install older versions of Ruby.

Installation

Run this command to install rbenv utility:

arch -x86_64 brew install rbenv

Ruby Installation & Version Management

To install any version of Ruby (in our case Ruby 2.6.8), run the following:

arch -x86_64 /bin/bash -c ‘rbenv install 2.6.8’

If you see an error message stating:

Build Failed

Enter the following command and run it:

arch -x86_64 /bin/bash -c ‘RUBY_CFLAGS="-w" rbenv install 2.6.8’

Voilà! You have the latest version of Ruby supported by GoodData Ruby SDK. All that is left to do is to list known Ruby versions on your machine and switch to the non-system one:

$ rbenv versions

* system (set by /Users/{user}/.rbenv/version)

  2.6.8

$ rbenv global 2.6.8

  system (set by /Users/{user}/.rbenv/version)

* 2.6.8

In the example above, we listed available Ruby installations in our system and switched to use the version 2.6.8 globally. You can also utilize rbenv to use a different Ruby version per project/folder.

Installing GoodData Gem

The final step is to add the GoodData gem to your chosen Ruby installation. To do so, run the following command:

gem install gooddata

This will install our desired gem with all its dependencies.


This topic has been closed for comments