Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Relationships

Why is it suggested that every rails command begin with bin?

In the examples and video I am seeing that the rails commands are beginning with "bin" prior to /rails. On my local machine I am able to run all of these commands just using rails e.g. "rails g model"

Is this due to the environment variable path?

Ursula Kuhn
Ursula Kuhn
9,722 Points

I have to since I'm working in a window on my Mac to tell the program to 'begin (bin)' and know where to search. But i also had the hassle of having to download and reformat my workspace since I'm stuck on a Mac. Not sure where you downloaded yours to to work from, but far as I gather, it's just a pointer. ~Ursa

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Sometimes your currently installed global version of Rails is not exactly the same as the project's version of Rails. If you precede teh command with bin/, you are making sure that you are running the version form the project. In most cases you can ignore that though. I've never used bin/ so far.

Understood, thanks Maciej!

David Clausen
David Clausen
11,403 Points

./bin/rails, bin is an actual folder. Inside the folder has several files that direct those are ruby files that are designed to run the specific version of the gem you specify in gemfile.

So when you type bin/rails you are in the project root folder and are telling it to look inside bin folder and run the file called rails, you then provide it an argument server.

These are binstubs autogenerated by Rails 4. You normally run the command as "bundle exec rails server". With binstubs you can type "bin/rails server"

Now if you are running multiple environments, or multiple gems version is where not typing "bin" will get you. Bundle ensure everything loads in proper order and with the right version. Not typing bin/respec can come back to bite you.

Rails supposedly checks for bundle first, so typing rails should be like typings 'bundle exec rails'. Rails is the exception to the rule. There is also a way to set it up that not using bin works too. But the default behavior is to practice using bin/rails, bin/rspec bin/rake ect...to get you in the habit of ensuring you are running the proper gemfiles and bundler is handling the package.