Ubuntu 20 > Apache 2.4 > Passenger 6 > ruby 2.7.4 > Rails 6.1 > `ruby script`
I'm invoking a ruby script via backticks from within a Rails controller (and collecting a return integer).
In production, somwhere in this chain, something is insisting on trying to run the ruby script with ruby 2.7.0 (the native system version) and complaining that it should be 2.7.4 (which it should).
The Rails app itself runs fine until I invoke a script.
When invoking the script, Passenger (I think?) is logging in the Apache error.log with
/home/rcm/.rbenv/versions/2.7.4/lib/ruby/2.7.0/bundler/definition.rb:495:in `validate_ruby!':
Your Ruby version is 2.7.0, but your Gemfile specified 2.7.4 (Bundler::RubyVersionMisMatch)
I have searched and tried numerous suggestions (most of which were already done).
All scripts use: #!/usr/bin/env ruby
$PATH includes /home/rcm/.rbenv/shims:/usr/local/sbin:... and the usual suspects (I see that's rather explicit with /home/rcm/.rbenv instead of ~/.rbenv --- does it matter?)
The apache .conf file has: PassengerRuby /home/rcm/.rbenv/versions/2.7.4/bin/ruby
I have .ruby-version files at every layer I can think of specifying 2.7.4
I have used rbenv to declare global 2.7.4.
I have updated bundler.
I have run bundle install.
Restarted apache, rebooted the system, etc.
I can't figure out where in the chain anything could be trying to run the script with 2.7.0.
It all works fine in dev mode on macOS and Ubuntu, and even works fine running the project in e -production mode with the built in Puma on both macOS and Ubuntu. Only in the full Apache > Passenger production mode is there a problem. So, I'm thinking it has to be Passenger that's confused, but it's running the Rails app itself just fine -- which makes me confused.
The screwy part is, this was all working fine, and "all of a sudden" I'm getting this failure. (No idea which bit I twiddled.)
Would appreciate any ideas to give me something new to chase. Thanks.
ruby is not necessarily the same as the ruby running Rails. It will run whatever the first one it finds in its PATH. Since this is running on a webserver, this will be different from the PATH of your own user.
Use bundle exec ruby to run the Ruby associated with the application.
The best thing to do is to not run a script, instead incorporate the script code as a class in your Rails project. This is faster and easier to test.
Related
Running a cron job via Whenever gem where rake "ts:index" is set to run at a certain frequency, the sphinx_index.log is returning an odd error (the only info in the log):
Your Ruby version is 1.9.3, but your Gemfile specified 2.2.3
if bundle exec rake ts:rebuild is run on the server manually, the process executes properly. (I have yet to test whether the indexing does actually occur and picks up changes). The Ubuntu server does have 2.2.3 installed, though it may have had 1.9.3 natively installed.
Why is this occurring and what is its consequence?
It sounds like cron isn't picking up your preferred Ruby version. If you're using RVM, then https://stackoverflow.com/a/24092907/54500 might be helpful? I'm not sure what's needed for other Ruby version managers.
Pat's answer is the correct thread of investigation.
Ben Scheirman's solution works as described for applications using the whenever gem. To use the proper ruby versions, rbenv's shims folder needs to be declared to the PATH.
I installed Ruby and Rails and set-up the PATH to "C:\Rails\Ruby2.3.0\bin", but when I try to run commands with rails, I get the error message:
The System cannot find the path specified.
I am able to run commands using ruby, and rails works if I use GitBash. How do I make it work on my normal command line?
Had the same problem here, installed the same way. Couldn't even run rails commands on GitBash, only way was going in C:\Rails\Ruby2.3.0\binthrough cmd and typing, for example, ruby rails new projectname. The rails new projectnamewouldn't work even in these conditions.
What I did was going in the Command Prompt with Ruby and Rails and entered gem install rails (which did not work on cmd). I also did gem install bundle. Both installed successfully and that fixed all consoles for me: cmd, GitBash (wasn't working for me), Command Prompt with Ruby and Rails and even cmder works with Rails now.
Hope this helps you.
Cheers.
If it's a simple question of locating the rails executable on Windows, then on later installs that use msys64 instead of DevKit, you'll find rails at the following folder:
c:\msys64\o-rdoc
Add this to your PATH or execute from that folder.
Your path may vary on 32-bit systems or if you changed the default install folder.
I have just built a RackSpace cloud server with Ubuntu 12 LTS and performed a "standard" Ruby on Rails installation. I created a user (bob) and added it to the sudu group.
I then logged out of root and logged in as bob. Then issued sudo su from the /home/bob directory. I then installed everything needed to run the Rails Application 'as root'.
I then installed the Rails code in /home/bob and passenger started up when I issued:
RAILS_ENV=production passenger start -p 3000
however, since I want to run multiple Rails applications on this server, I then created another directory /home/bob/newapp and installed Rails code there. (ideally I would want to put all the different Rails applications in their own subdirectory below /home/bob)
When I issue the command (shown below) from /home/bob/newapp
RAILS_ENV=production passenger start -p 3000
I get
passenger: command not found
why is passenger only accessible from /home/bob ?
NEWS: just discovered, passenger is 'available' until the moment I complete the edit of the content of /config/database.yml thus as long as I do NOT edit the database.yml file, passenger will start. After I edit database.yml the "passenger: command not found" appears. How bizarre is that?
SNAP: looks like when I installed passenger it used Ruby-2.1.1 however the old application wants ruby-1.9.3-p194. I need to figure out how to get passenger to run with ruby 1.9.3 or install a second version of passenger (???)
More News:
Thank you,Hongli, for your response. I followed your links/suggestion to read the passenger documentation. I had read it before without recognizing the needed information. This time I found the "magical" command:
rvm-exec ruby-version ruby -S (eg: rvm-exec ruby-1.9.3-p194 ruby -S )
this has turned out to be very helpful, although I did end up following a process which has resulted in two different version of passenger being installed.
Read the About environment variables section of the Phusion Passenger manual to learn what "command not found" errors are, why they occur, and what you can generally do about them.
In your case, entering /home/bob automatically makes RVM change your PATH to include a specific Ruby version's bin directory. Read the When the system has multiple Ruby interpreters section of the Phusion Passenger manual to learn how to deal with that.
The article Hongli suggested I read definitely moved me in the correct direction.
The use of: rvm-exec 'ruby-version' ruby -S allows me to get passenger started, provided a version of passenger has been installed using the version of ruby required by the Rails application.
Thus if I load up a Rails application built with ruby-1.9.3-p194, I will need a version of passenger installed with the same version of ruby.
If I load up another Rails application built with ruby-1.9.3-p286, I will need a version of passenger installed with that version of ruby.
Then starting each version of passenger can be accomplished with the rvm-exec command with the appropriate ruby version.
Perhaps there is a more elegant solution, but the above works for me.
I followed all of the directions and this is the result.
I'm in the process of creating the .rvmrc file at my application root path, as well as the setup_load_paths.rb file in my /config folder as described here. I did all that, and then I realized my computer is using ruby 1.9.3p194. While the EC instances is using 1.9.3p286. So I'm in the process of matching them up and re-creating the .rvmrc file.
While doing that, I noticed that the beanstalk ec2 server doesn't even have rails installed. I should be able to type rails --version I assume and see the version like I can on my computer and with ruby --version on the server. So I'm installing RVM, with and rails (as I've done in the past) on my new beanstalk ec2 server. But in general, it seems this all defeats the purpose. It's supposed to be somewhat automatic. Installing rails definitely doesn't sound right. Was it installed another way on the server?
Any advice on how to get the new beanstalk support for ROR working? What am I doing wrong?
From the error in your passenger exception it looks like Bundler was unable to locate the Ascii85 gem in your remote sources. Your remote source should be listed in your Gemfile at the top line in the form:
source :rubygems
If this is not working, try specifying the source explicitly in the form:
source 'http://rubygems.org'
Note that you should not be doing anything special for RVM/Passenger integration in a deploy. In fact, any extra specialized integration may actually cause problems with Elastic Beanstalk if any platform details change. You should be building your application using standard Rails conventions.
As far as rails -v failing: Rails is brought in via your Gemfile, which relies on bundle install succeeding. Your passenger error shows that Bundler failed to resolve your dependencies against your remote sources, which likely means that Rails was also not installed. In other words, Rails will only be available if the bundle installation succeeds.
I'm deploying a rails application using Capistrano to a shared server (on WebFaction). This means there are several different Ruby version installed there.
Everything works fine until I want to run some rake tasks. These tasks fail by saying I don't have the right RubyGems version.
From this thread I understood that fixing it would be as easy as adding the full path to the correct rake folder to my rake commands. I tried that but failed again, now because the Ruby interpreter that is used is the wrong one.
I assumed that capistrano would use the username/password I gave it to run commands on the server but it seems not to be the case.
Am I missing something? How can I fix that?
Thanks!
This is indeed a path issue. I solved it by symlinking my ruby, rake, and rails executables to my path. For instance, if the executables that you want (but are failing to work) are located at /opt/ruby/bin/ruby, you'll symlink it to:
ln -s /opt/ruby/bin/ruby /usr/local/bin/ruby