Installing Ruby on Rails with RVMThis tutorial will show you how to install and configure a Ruby on Rails project within a web app. If you do not have a Web Apps section in your hosting Control Panel, then this tutorial is not suitable for your particular hosting environment. You can ask your hosting provider for more information, or you can seek assistance through our ticketing system. Important: Throughout this tutorial, 'example' is used as the username for the account. Wherever you see 'example', you should replace it with the actual username for your hosting account. We will set up a Ruby environment by using Ruby Version Manager (RVM). RVM enables you to manage and work with multiple Ruby environments and allows you to switch between them. This way, you can have multiple projects on the same account, each using a different version of Ruby and different gems. 1. Connect to your account via SSH
2. Install and configure Ruby Version Manager (RVM)Most of the installation steps have been obtained from the RVM installation documentation.
echo "export GNUPGHOME=$HOME/private/.gnupg" >> ~/.bashrcReload your bash profile: curl -sSL https://rvm.io/mpapis.asc | gpg --import - && curl -sSL https://rvm.io/pkuczynski.asc | gpg --import - && gpgconf --kill gpg-agent
curl -sSL https://get.rvm.io | grep -v 'partition=`df' | bash -s -- --path ~/private/.rvm --ignore-dotfiles You should get the following output: RVM was installed in the ~/private/.rvm directory on your account * To start using RVM, you need to run the command listed below in all your open shell windows (in rare cases you need to reopen all shell windows): source ~/private/.rvm/scripts/rvm
echo "source $HOME/private/.rvm/scripts/rvm" >> ~/.bashrc
type rvm | head -n 1 You should get the following output: rvm is a function
sed -i "/__rvm_calculate_space_free/c\__free_space=9999M" ~/private/.rvm/scripts/functions/manage/base_install ~/private/.rvm/scripts/migrate The patch sets an arbitrary value of 9999M for the __free_space variable. In case you update RVM to a newer version, you may need to apply the patch again.
rvm autolibs 0 In case some gem installation fails or your project does not run due to a missing dependency, you can contact our support team for assistance. You can check for any missing dependencies with the following command: 3. Install RubyRVM could run out of memory when compiling Ruby. Therefore, you should limit the compilation to 3 simultaneous threads by adding the following setting to ~/private/.rvm/scripts/functions/rvmrc: You can now install the latest stable version of Ruby by running: rvm install ruby --latest RVM will compile Ruby from source and install a global gemset. At the time of this writing, the latest stable Ruby is 3.1.2. We will use this version in the examples that follow. You can switch to that Ruby version with: rvm use 3.1.2 4. Install Rails and create a project.You can install Rails directly into the global gemset. However, many developers prefer to keep the global gemset sparse and install Rails into a project-specific gemsets, so that each project has the appropriate version of Rails.
mkdir ~/private/blog
rvm use ruby-3.1.2@blog --ruby-version --create The name of our project and our gemset is blog. The option “—ruby-version” creates .ruby-version and .ruby-gemset files in the root directory. RVM recognizes these files in an application’s root directory and loads the required version of Ruby and the correct gemset whenever you enter the directory.
gem install rails Rails will be installed in the gemset blog. This can take a while as Rails has a lot of gem dependencies.
rails new . With '.' (a dot) as project name, the command creates a new project in the current directory, and the project name is the same as the name of the directory. You may be asked if .ruby-version should be overwritten. The old and new files have the same content, so both 'yes' and 'no' are valid options. In case some gems were not installed correctly locally, you can fix this by running the following command: bundle install 5. Create and configure the Web AppOpen the Web Apps section of your hosting Control Panel and create a new app with the following settings: • Choose Custom as the engine. rails server However, to run a Ruby application as a web app with RVM, you need to first load the corresponding RVM environment and then run the executable of your app. For every installed ruby and gemset, RVM creates environment files. You can list the environment file for this project by running the following command in the project directory: rvm env --path RVM will return the path to the environment file: /home/example/private/.rvm/environments/ruby-3.1.2@blog You can use the 'source' command to load this environment file when starting Rails. Both commands combined are: source /home/example/private/.rvm/environments/ruby-3.1.2@blog && rails server You should enter this combined command in the Start command field of the web app. Once you are finished, the project should look like the following:
|