The problem
To begin working on a Rails app I need to do things like starting a server, starting a console, ensure background processes are running, start a terminal window so I can watch logs, start a text editor etc etc.
Doing all this is tedious. Wouldn’t it be nice if we could just do something like?
1
| |
Well you can!
Tmux
Tmux is a ‘terminal multiplexer’. What the hell’s that? It basially allows you to create terminal sessions - similar to GNU Screen where you can detach from a session and come back later. If you are not familiar with tmux there are a few good resources available
- A quick tmux (terminal multiplexer) screencast (a better GNU screen)
- Love, hate, & tmux
- TMUX - The Terminal Multiplexer (Part 1)
- TMUX - The Terminal Multiplexer (Part 2)
You can install tmux with homebrew
1
| |
It takes a little reading and configuring but is well worth effort if you are a heavy terminal user.
Tmuxinator
Tmuxinator is an excellent gem that lets you define the layouts of your tmux sessions.
You can install tmuxinator from RubyGems
1
| |
By defining a yaml file we can layout things exactly how we want them.
1 2 3 4 5 6 7 8 9 10 | |
Then you can start your session with start_myapp and your layout will be ready for you. Here’s a screenshot from the documentation:

There’s excellent documentation on using tmuxinator in the project README
Foreman
Enter the final piece of the jigsaw - foreman. Foreman is a gem that lets you manage background processes associated with your application through a Procfile. You just add any processes you want to be started into the Procfile and you are done. Here’s an example
1 2 3 4 5 | |
You can then start these process by running
1
| |
The processes will run in the foreground and spit out any logs messages to standard output - perfect for development.
Using foreman you can add a tab to tmuxinator that will start your processes and have a nice log of what they are doing. We have a neat way of starting any background processes in our app within the context of our unified tmux development environment.
So with one command we can set things up exactly the way we want and get straight into developing.
Alternatives
This technique will also work well for screen and regular terminal users with the Screeninator and Terminitor gems so if you are not sold on tmux you can still use it.