On my system (OS X), I have an application running on Rails 3.1.0, ruby 1.8.7.
I installed Vagrant and set it up with Ubuntu virtual. I created a new project ABC from within the virtual machine and installed ruby 1.9.3 and Rails 3.2.6, on the virtual machine.
Now, when I exit Vagrant virtual machine and want to ssh into it again, from the ABC project directory, it struggles with a conflict in the ABC project's Gemfile:
~/.rvm/gems/ruby-1.8.7-p358#global/gems/bundler-1.1.4/lib/bundler/spec_set.rb:90:in 'materialize': Could not find actionmailer-3.2.6 in any of the sources (Bundler::GemNotFound)
When I remove the Gemfile from ABC project's directory, I can use Vagrant without any issue.
Why is Vagrant checking out project's Gemfile, instead of just running the virtual machine?
Anyone experienced something like this before?
Vagrant uses Gemfile for plugins.
See the documentation for plugins https://docs.vagrantup.com/v2/plugins/packaging.html.
So vagrant thinks that your rails gems are plugins for vagrant and fails.
My current setup uses Vagrantfile detached from rails directory.
I ended up with this settings after I started using Puppet provision scripts, various bash scripts, project documentation folder outside of rails etc.
It makes more sense to keep rails app as clean as possible and not poisoning it with local development tools files (Vagrantfile).
The question is still valid though. I'm not sure whether this qualifies for an Issue report on github...
Related
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.
I have a working ruby on rails app in my local machine running on localhost(REST APi's). I want to deploy it on remote linux server.
I searched it over google, All I got was installing ruby, rails, nginux and others. It's really confusing. To make my app to work in rails environment in linux, is it really necessary to install the entire ruby and rails. Or, is there any binary executable available where we can use it without installing.
What is minimum required software to install or configuration needed to be set to make my app work in production environment?
(For Example, when I deploy nodejs app, All I need is to put the linux nodejs binaries in server without the need for installing the entire nodejs software)
Any help is appreciated!
The process of setting up your production server will be pretty much the same as with setting up your development machine in terms of installing Ruby and its dependencies. There are no binaries that you can just copy over. In addition to that you'll have to install and set up a web server like Apache or nginx.
I recommend this guide by Digital Ocean. It goes through everything from installing ruby, to setting up the database, to configuring the web server.
They have a couple more (here and here), which seem to be very similar, using different application and web servers, but I haven't read them.
You need to do the following:
1) Ensure that you have an installation of the Ruby language, either via your Linux package manager or with rvm or the like. I recommend it be a recent version (2.2+).
2) Copy over your Rails source tree.
3) gem install bundle
4) bundle install (in the project root directory)
I'm using Ruby 2.1 and Rails 4.1 on Windows 7. Whenever I run bundle install, all gems are installed in the system path c:/Ruby21/lib/ruby/gems/2.1.0/gems/. I also found the vendor directory in my project.
Coming from PHP composer and node.js npm background, all dependencies should be locally installed in the project vendor folder or node_modules folder. So, my questions are:
Should I install gems in the system path or vendor/bundle?
If all gems or some gems should be installed in the system path, how could it affect the production environment where I may not have shell access?
Should all gems or specific gems be installed in vendor/bundle?
How can I install gems in vendor/bundle?
When you run bundle install, you are using a tool called Bundler.
Bundler takes care of managing your dependencies in a similar way as Composer, but instead of installing everything in the project folder, it installs your gems system-wide, that are shared among all your projects. It keeps track of what project requires which libraries by using the Gemfile in your project folder. So, you should just let Bundler do its thing, it does it very well and is the standard package manager for Rails.
If your host supports Ruby and Rails applications (for example, a PaaS like Heroku), it definitely will support Bundler and all the necessary gems will be installed. If you're talking about a cheap shared hosting without shell access, you won't be able to deploy a Ruby application there anyway because you will need to install the actual Ruby interpreter and other things, which would require shell access.
No.
You shouldn't. There's this article describing how to do it, but it seems to me that
countless times where installing gems globally leaked into other projects on the same machine and led to weird behavior that was annoying to debug
has only ever happened to the author of this article, and I don't think Bundler is at fault. In any case, you should always prepend gem commands with bundle exec (as in bundle exec rspec) and you will never have the mentioned problem. bundle exec makes sure that when you execute a command from a gem, the correct version defined in your Gemfile is called, it is important if you have several version of the same gem installed in your system.
A few years ago when RVM was popular, gemsets achieved a similar goal but got mostly deprecated by rbenv and Bundler.
I am unable to get a remote SDK to run from my client workstation. It complains that the remote SDK doesn't have rails installed.
Here is my environment:
Windows 8 Workstation:
Rubymine
CentOS 7 Development Server:
rvm (installed Ruby 2.1.2)
/opt/learning_stuff (git repo with app in there)
bundle install was ran
A few diagnostic commands yield these results:
# which ruby
/usr/local/rvm/rubies/ruby-2.1.2/bin/ruby
# which rails
/usr/local/rvm/gems/ruby-2.1.2/bin/rails
How do I get rubymine to see the rails installation? Do I need to drop rvm and install from source?
In Rubymine 7.1, I used my gem directory instead of the path to the ruby executable in the "Ruby interpreter path". It found my gems for my project, and performed the sync.
Not a solution to the actual problem, but what I ended up doing is just figuring out how to make the application work on both my windows localmachine and on my linux dev box. The benefit to this is that my application is now cross platform even though I don't need it to be.
I have a RoR application running on box1...it obviously has Ruby, RubyGems, and Rails installed on that box, along with a few other gems.
I want to copy this whole set-up so it runs independentally on box2 as well.
Neither box has an internet connection, but an internet connection is available on another machine.
So as far as I can see, I need to-
Install Ruby on box2 (I have an RPM, no problem)
Install RubyGems on box2 (I have an RPM, no problem)
Install Rails (How do i do this?)
Copy over entire Rails app directory onto box2?
The only guidance on the Ruby on Rails site is to run gem install rails but I cannot do this without an internet connection.
So can I just run bundle package on box1, then copy over the resulting gem files onto box2 and do a local gem install on each one to install them?
Or can I simply copy 'usr/local/lib/ruby/gems/1.9.1/gems' directory onto box2?
Secondly, I plan on packing my Rails app into an RPM so I can easily deploy it wherever I want...can I just include my gem files (resulting from bundle package) in the RPM directory structure, and then direct the RPM in the .spec file to do a gem install during installation? That way it'll install the required gems as the RPM is being installed.
It's possible I'm overlooking a much simpler method, or misunderstanding something, if so, please enlighten me. Any help?
Take a look at Vagrant and the Railscasts episode.
Vagrant will solve your "deploy anywhere" problem by putting everything in a virtual machine that has all your gems installed.
Of course, this won't solve your immediate problem due to lack of internet access but it does sound like you're on the right track.