Managing gems for your Rails applications

Rails applications installed via Opalstack's Rails installer use Ruby gems in two locations within the application directory:

  • env which contains application environment for the core Ruby on Rails software
  • myproject (or your own project directory) which contains your Rails project and its dependencies.

Before you can add, remove, upgrade, or downgrade gems in your Rails application directory you must first configure your shell environment by executing the following commands, replacing myapp with your application name and myproject with your project name:

export APPDIR=$HOME/apps/myapp
export PROJECTDIR=$APPDIR/myproject
export GEM_HOME=$APPDIR/env
export PATH=$PROJECTDIR/bin:$GEM_HOME/bin:$PATH

Once you have configured your shell environment you're ready to manage your gems as follows

Working with gems in your application environment

If you need to install additional gems or modify gems in the application environment:

1

Prepare your shell environment as described above.

2

Use the gem command to install the gems that you need.

For example, if you want to connect your Rails project to a MariaDB database you will need the mysql2 gem which you can install with the following command:

gem install mysql2

Working with gems in your Rails project

If you need to install additional gems or modify gems in Rails project:

1

Prepare your shell environment as described above.

2

Switch to your project directory:

cd $PROJECTDIR
3

Update the Gemfile in your Rails project directory to specify the gems for your project.

4

Install the gems with the bundle command:

bundle install