0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Install Ruby on Rails on Debian 12

Posted at

I recently tried to Install Ruby on Rails on Debian 12 for a project, and while I eventually got it working, the process was far from smooth. Here’s what I did, along with the issues I faced, in case it helps others avoid the same pitfalls.


Step 1: Install Ruby

I started by installing Ruby using the default package manager, but ran into version issues. The default Ruby version on Debian 12 was too old for Rails, so I had to remove it and install a newer version using rbenv. Here’s what I did:

  1. Remove the default Ruby (if installed):

    sudo apt remove ruby
    
  2. Install dependencies for rbenv:

    sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libncurses5-dev libffi-dev libgdbm-dev
    
  3. Install rbenv and Ruby:

    curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-installer | bash
    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    echo 'eval "$(rbenv init -)"' >> ~/.bashrc
    source ~/.bashrc
    rbenv install 3.2.2  # Replace with the version you need
    rbenv global 3.2.2
    

    Problem: After installing Ruby, running ruby -v gave me an error about missing libraries. I had to manually install libssl-dev and libreadline-dev to fix it.

Step 2: Install Rails

Once Ruby was installed, I tried to install Rails using gem install rails, but it failed due to permission issues. Here’s how I fixed it:

  1. Install Rails:

    gem install rails
    

    Problem: The command failed with a permission error. I had to use --user-install to install Rails locally:

    gem install rails --user-install
    
  2. Add gems to PATH:
    I added the following to my .bashrc to ensure Rails commands were recognized:

    export PATH="$HOME/.gem/ruby/3.2.2/bin:$PATH"
    source ~/.bashrc
    

Step 3: Set Up a Rails Project

I created a new Rails project, but ran into database configuration issues:

  1. Create a new project:

    rails new myapp
    

    Problem: The rails new command failed because bundler wasn’t installed. I had to install it manually:

    gem install bundler
    
  2. Install dependencies:
    After fixing bundler, I ran:

    bundle install
    

    Problem: The pg gem (for PostgreSQL) failed to install because I didn’t have the PostgreSQL development libraries. I fixed it by running:

    sudo apt install libpq-dev
    

Step 4: Run the Rails Server

Finally, I tried to run the Rails server, but it wouldn’t start:

  1. Start the server:

    rails server
    

    Problem: The server failed to start because JavaScript runtime was missing. I installed Node.js to fix it:

    sudo apt install nodejs
    

Conclusion

While I eventually managed to Install Ruby on Rails on Debian 12, the process was frustrating due to missing dependencies and permission issues. If you’re trying this, make sure to:

  • Use rbenv for Ruby installation.
  • Install all necessary development libraries (e.g., libssl-dev, libpq-dev, nodejs).
  • Use --user-install if you encounter permission errors.
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?