Ruby: Setting up a Ruby project

This documentation is part of the Getting started guide. View the full guide here: Getting started with Ruby on Rails.

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use Ruby cloud solution that provides a host of benefits, including:

  • Deploy your application in seconds with a simple git push.
  • Use your own domain name and benefit from the automatic configuration of HTTPS certificates for enhanced security.
  • Enjoy peace of mind with automatic backups, one-click updates, and straightforward, transparent, and predictable pricing.
  • Get optimal performance and robust security thanks to a private and dedicated VM.

Save time and simplify your life: it only takes 5 minutes to try Stackhero's Ruby cloud hosting solution!

Starting a new Ruby project is straightforward. Follow these steps to get going:

  1. First, make sure you have the latest version of Ruby installed on your system. You can verify this by executing the following command in your terminal:

    asdf install ruby latest \
      && asdf global ruby latest
    

    If you have not installed asdf yet, you will need to do so before proceeding. Please refer to the official asdf documentation for detailed installation instructions.

    Alternatively, you can use Stackhero Code-Hero, an online development solution where all necessary tools are pre-installed. This platform allows you to start coding immediately without manual installation.

  2. Next, install Rails. Rails is distributed as a RubyGem which makes installation straightforward:

    gem install rails
    
  3. Then, create a new Rails application named my_app and specify the Ruby version using these commands:

    rails new my_app
    cd my_app
    asdf local ruby latest
    
  4. To launch the Rails server, run the following command:

    bin/rails server
    

    Ruby on Rails welcome screenRuby on Rails welcome screen

These steps create a new Ruby project while setting the appropriate Ruby version. This lays a solid foundation for your application development.

Important: When executing the rails new command, a local Git repository is automatically created for your Ruby project. However, it is not yet linked to a remote version control service.

For proper version control and data safety, you are encouraged to connect your project to a hosting service such as GitLab, GitHub, or Bitbucket.

If you need a repository hosting service, Stackhero offers a GitLab cloud service that can be set up in just 2 minutes.

When using an online development solution like Stackhero Code-Hero, you need to adjust your config/environments/development.rb file. Add the following configuration near the final end keyword. Replace <XXXXXX>.stackhero-network.com with your actual server hostname:

config.hosts << "<XXXXXX>.stackhero-network.com"

Hosts configurations exampleHosts configurations example

Finally, start the Rails server with this command:

bin/rails server -b 0.0.0.0

This command ensures that the Rails server is accessible from any IP address, which is especially useful when working remotely via Stackhero Code-Hero.