Alex Ghiculescu
Alex Ghiculescu

Reputation: 7540

No such file or directory when making system calls in Rails production env

I'm getting some annoying errors when trying to make system calls in the rails console in a production environment.

Loading production environment (Rails 4.0.2)
2.0.0 :001 > `hostname`
bin/rails: No such file or directory - hostname
 => nil

It works fine in irb.

$ irb
2.0.0-p353 :001 > `hostname`
=> "app-1\n"

Same thing happens on my local machine. rails c is fine but rails c production gives the error above.

ruby -v outputs ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]

rails --version outputs Rails 4.0.2

I'm not really sure where to start debugging this so any advice is welcome! I have tried running rake rails:update:bin, based on "bin/rails: No such file or directory" w/ Ruby 2 & Rails 4 on Heroku, but it didn't seem to make a difference. Any ideas?

Upvotes: 1

Views: 2178

Answers (1)

Tim Peters
Tim Peters

Reputation: 4144

The difference in the PATH is the problem. You'll need to look into your code or hosting environment to find out how the PATH is being set in the rails app. It could be in the app itself, or whatever app server is launching the app - details can vary wildly.

Your rails console output:

"$HOME/.rvm/gems/ruby-1.9.3-p429/bin:$HOME/.rvm/bin:$PATH"

indicates that something is trying to add to the path, but it is inserting literal dollar signs instead of expanding the existing environment variable. For example in a shell script setting a path, if you used the wrong quote symbols you'd see something like what you've got.

export PATH="$HOME/.rvm/gems/ruby-1.9.3-p429/bin:$HOME/.rvm/bin:$PATH"   # right
export PATH='$HOME/.rvm/gems/ruby-1.9.3-p429/bin:$HOME/.rvm/bin:$PATH'   # wrong

I hope this points you in the right direction :)

Upvotes: 1

Related Questions