Search code examples
ruby-on-rails-3nginxmultiple-projects

Running multiple Rails projects on Ubuntu


I'm brand new to Rails. I have one Rails project on my machine, but I'd like to create a 2nd project from scratch and I'm having trouble figuring out where and how to set it up. Specifically:

  • My current project is located in the Projects/project1 directory. I'd like to have it located in Projects/project2. Do just reinstall Rails into that directory?
  • I still need access to project1. How do I switch back and forth between the two projects in terms of browser access? Will it be a separate server? Do I have to edit a file to switch?
  • Anything else you think I might need to know in order to manage multiple projects. Please assume that I know nothing about the setup as I'm just getting started.

Solution

  • My current project is located in the Projects/project1 directory. I'd like to have it located in Projects/project2. Do just reinstall Rails into that directory?

    Just create a new Rails project in that directory by running rails new:

    $ cd Projects
    $ rails new project2
    

    You'll have a new (empty) Rails application in project2.

    I still need access to project1. How do I switch back and forth between the two projects in terms of browser access? Will it be a separate server? Do I have to edit a file to switch?

    Assuming you're running local servers via rails server, you can specify which port your server is running on via -p.

    Given a Rails project, you can listen on localhost:3001 by executing

    $ ./script/rails server -p 3001
    

    To run multiple Rails projects locally, make sure they're all running on a unique port.

    Anything else you think I might need to know in order to manage multiple projects. Please assume that I know nothing about the setup as I'm just getting started.

    Depending on your platform, you should look into Pow or Passenger which automate the process of deploying multiple Rails apps to a single server.