I have a simple Thin webserver I want to start with Upstart. However, upstart needs to be run with sudo which can't see all the RVM gems like Thin. rvmsudo hasn't helped me either. What's the solution for upstart to see your RVM gems?
RVM is really more for personal use. For a system service, I would just install the version of Ruby you want (someplace that doesn't conflict with the system version, like /usr/local/) and use Bundler in deployment mode to get the gemset.
Have you considered creating a gemset and defaulting to a particular gemset for your project?
Default to a Ruby: rvm use 1.9.3
Create a Gemset Manually (One time): rvm gemset create
project-name
Switch to this Gemset: rvm gemset use project-name
See if this works, you might be able to later on add this to your .rvmrc file for automatic context switching. But give it a shot first and see if this works.
Related
I worked on some project when in some moment I have to change Ruby version for some other project. Now when I want to go back to first project, I'm getting some errors because of Ruby version. The question is how to change Ruby version(currently I'm on RVM-installed Ruby 2.5.1) and want to back to Ruby 2.4.5 but it wasn't installed via Rvm or Rbenv, just clean installation.
I know how to change Ruby version via Rvm, but how to change to version which is not installed with any addition (Rvm or Rbenv)
Even though this doesn't answer your question directly, I would recommend against using both RVM Ruby and system Ruby together. RVM was not designed to work that way and every issue arising from this kind of installation would be quite difficult to debug, particularly if you are a beginner.
So the easiest way to go would be to remove the system Ruby completely and create a 2nd RVM gemset for your other project. (This is how RVM is intended to be used, actually.)
See doc: https://rvm.io/gemsets/creating
https://rvm.io/gemsets/basics
If you have more then one projects with different ruby versions then we need to use rvm gemsets to avoid conflicts.
Steps to be followed:
rvm gemset create sriharsh
rvm use 2.2.1#sriharsh --create
rvm gemset list (to check list of gemsets)
rvm list (list of rvm rubbies)
However, if you are using Bundler then you don't need to use RVM Gemsets. Prepending any command with bundle exec will execute it in the context of the project's Gemfile.
For ex:
bundle exec rails s
I am trying to use a specific version of ruby on a particular project. I looked into the RVM and rbenv packages, but had little success with any of them.
These are the steps I took:
create project directory and navigate to it;
run rbenv install 2.3.1; after navigating to ~/.rbenv/versions I can see a "2.3.1" in there;
running "rbenv local" also echos 2.3.1;
My Gemfile is as follows:
ruby '2.3.1'
source 'https://rubygems.org/' do
gem 'test-kitchen'
gem 'kitchen-terraform'
end
However, when I run bundle install i get the following error:
Your Ruby version is 2.5.1, but your Gemfile specified 2.3.1
Its my first time working with Ruby, so I am struggling a little. I appreciate all help, and can provide more details if required.
If you store the ruby version of your project in .ruby-version and the gemset (i.e. gem list workspace) in .ruby-gemset of your project (which I recommend doing if the specific version is important to you), rvm should pick this up when you cd into your project directory. Sometimes it doesn't however depending on your setup or installation, in which case you can choose them explicitly with:
rvm use `cat .ruby-version`
rvm gemset use `cat .ruby-gemset
which I add to any installation scripts for example. You may need to run gem install bundler before running bundle install the first time you use the new gemset.
Set your default rbenv version like this:
$ rbenv shell jruby-1.7.1
See in: https://github.com/rbenv/rbenv#rbenv-shell
The following code lives inside my rails app's root folder and daemonizes/runs myserver.rb.
# myserver_control.rb
require 'rubygems'
require 'daemons' # causes 'no such file to load -- daemons' error since gem reinstall with rvm
#options = {
# options defined
}
Daemons.run('myserver.rb', #options)
It was working just fine until I installed rvm and now it can't seem to find the daemons gem. I have a feeling maybe the above is searching for the daemons gem in a system wide folder somewhere? Instead of being able to use the rvm installed daemons gem? How do I install the daemons gem on a system level where it can find it? OR how do I make it so it can find the rvm installed gem?
Currently I do not even have a 'system' gem set. How would I install gems on the system level after having already installed rvm?
If wishing to use the system ruby and gems you can type in
rvm use system
which will allow to use the system installed ruby and gems, but I think this kinda of defeats the purpose of using RVM I would instead install a default ruby in RVM and install any gems into that. To set a default Ruby after you have installed it, type this
rvm --default use 1.9.2
Edit
Based on comment your problem lies with running sudo, this creates a new subshell and different instance of rvm
RVM uses a concept of gemsets, which are unique groups of gems that you can use, most often specific to ruby versions (although you can make them specific to applications or global).
RVM will change your GEM_HOME when changing ruby versions, which tells ru ygems where your gems are installed. So when you installed RVM, you created a new blank gemset and RVM told rubygems to use that.
This is because gems are not always cross compatible between rubygems.
However, if you just writing rails apps, you should ignore the above for now and use bundler. Place 'gem "daemon"' I am your Gemfile and run bundle update from your app root directory.
Bundle helps you maintain gems on a per app basis, which means your app won't break if you upgrade a gem somewhere else. Using it and knowing how it works is best practices. Good luck.
I have a git-repo which i clone onto my servers to do some administrative stuff. Most of the scripts are ruby, i need some gems. Until now i just installed the gems using sudo, but that doesn't seem like a good idea.
I tried rvm and bundler, but i'm still not sure how to do it properly.
Usually i clone the repository into /root and symlink the scripts into /usr/local/bin. I think what i want is the gems to be installed into the repository itself, so that other people can use my scripts without fu*king up their rubygems installation.
Any ideas on how to proceed? I also don't know how to specify the gems in a way that the script in /usr/local/bin still find them.
with RVM you can select separate gemset for gems and create a wrapper that will make binaries available always in PATH.
here is example with haml:
rvm use 1.9.3#tools --install --create
gem install haml
rvm wrapper 1.9.3#tools --no-prefix haml
I have been using RVM to manage my Rubies and gems.
When I first installed RVM, the Ruby version that I installed was 1.9.2-p0. I recently installed Ruby 1.9.2-p136, which created a new Ruby in the RVM.
My problem is I want to use the latest version of Ruby but all of the gems I installed were installed under the 1.9.2-p0 directory, because RVM keeps gems completely separate between Rubies, and I want to be able to use those gems with my new version, p-136 without having to reinstall them all.
Is there a way I can get my gems from my p-0 Ruby to work with my p-136 Ruby?
You can use copy in rvm
$ rvm gemset copy 1.9.2-p0 1.9.2-p136
See more about the rvm copy command
This is the fastest way to get your gems moved over and it wont reinstall everything, just copy them over. But once you've got that squared away I'd do as the others are suggesting and start using gemsets. It's a nice way to group the gems you use in your projects.
This might help: http://rvm.io/gemsets/initial/
Basically, if you setup a global gemset configuration, those gems will be used for every ruby version you install.
You need to check out gemsets and export your current gems.
rvm gemset export
Read the gemset docs for more information.
You can copy a gemset from one ruby to another.
rvm copy
$ rvm gemset copy 2.1.1#rails4 2.1.2#rails4