This 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.
Most of the installation steps have been obtained from the RVM installation documentation.
echo "export GNUPGHOME=$HOME/private/.gnupg" >> ~/.bashrcReload your bash profile:
source ~/.bashrcDownload and import the keys:
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:
rvm requirements
RVM 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:
echo "rvm_make_flags=( -j 3 )" >> ~/private/.rvm/scripts/functions/rvmrcTo make sure that all changes were applied, reload RVM:
rvm reload
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
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
cd ~/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
Open the Web Apps section of your hosting Control Panel and create a new app with the following settings:
• Choose Custom as the engine.
• Enter a name for your app. It is only for internal reference to the app. In this example, it is Blog.
• Choose a subdomain at which you wish to access the app. In this example, we choose the "www" subdomain: www.example.com.
• Leave the default web access path / (forward slash). For example, if you enter /rails, you will be able to access the app at http://www.example.com/rails. You do not need to create the directory.
• A port will be automatically assigned to the new project. It will be transparent to your users. It will be displayed in the app list after creating the project. You should note it as you will need it at the next step. In this example, it is 44181.
• For deployment directory select the directory where the project is located. In this case it is /private/blog.
• The Rails web server can be started with the following command:
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:
port ENV.fetch("PORT") { 44181 }
All prices are in USD. No setup fees. Minimum contract period for shared hosting services - 12 months. Full prepayment for the contract period. 100-day money-back guarantee. No automatic renewal. Fees for domain registrations and SSL certificates cannot be refunded in case of an early contract termination.
ICDSoft 2001-2024 © All rights reserved
Terms of Use
|
Legal notice
|
Privacy
|
Reseller terms