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
Related
I've been working on a blog using Jekyll so I installed Ruby with this command from the Jekyll doc:
sudo apt-get install ruby ruby-dev build-essential
Then I installed the gems directory to my home folder. I tried out a lot of different themes and just run bundle install when my terminal said I was missing any dependencies. Now I have a lot of packages installed inside the gems folder. Is there a way for me remove unnecessary gems and start over without uninstall gems?
It is highly recommend to not use system ruby but use a ruby version manager. One reason is that you won't have to use sudo before your gem commands.
If you want to remove all your current gems you should be able to just do
gem uninstall --all
But you might need to prepend it with sudo gem uninstall --all
If you intend to do any longer term work / multiple projects with ruby, I recommend using RVM. You can find detailed install instructions here
Some prefer rbenv however it's install instructions seem to be focused on MacOS, so if you're on linux, I dunno.
You can just run:
gem uninstall [gemname]
to remove them one at a time.
How do I install the gem command locally?
I'm on a shared hosting, the machine has ruby installed, but I need to get the gem command installed to $HOME/opt so I can install ruby modules like sass.
You can install rvm into the $HOME/.rvm folder, and use with it non-system rubies, and gemsets, just install required ruby, and create newly named gemset from within the rvm session. All of them will be stored in yuor home folder.
In case if you strictly with to use $HOME/opt, you shell install the rvm, then move its folder to the $HOME/opt, set properly PATH environment variable up, and fix call to rvm in the $HOME/.bash_profile.
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 installed Ruby 1.9.2 using homebrew, then installed RVM.
I want to point RVM to the version I have in my Cellar folder. How can I make rvm --default 1.9.1 point to the one in Cellar without having to reinstall it again using RVM?
You can't do it and get the right behavior.
RVM works within its own directory when running as a single-user's sandbox. Any Ruby it controls will exist in your ~/.rvm directory.
Anything outside of RVM's control will be considered the system setting, and it will be up to you to manage whether that is the regular Ruby installed in /usr/bin or /usr/local/bin or in /opt or wherever.
In my opinion, you should let RVM manage the Ruby installations. It is very slick and has rapidly become the favored way to manage Ruby development environments on Linux and Mac OS.
You could try creating aliases from the Cellar folder to the appropriate place in the ~/.rvm, but RVM modifies some things during its install process, such as gem, which would not be done in the Homebrew-installed folder, and would cause RVM's gem support to break for that Ruby version.
I have installed Ruby 1.9.2 from source. But it seems there is some trouble recognizing the bundler gem which I have already installed.
My /etc/environment file:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"
It looks like my gems are in /usr/local/ruby/gems/1.9.1/gems/.
In my rails application when I attempt to run sudo bundle install I get an error:
sudo: bundle: command not found
Also, why do the directories say 1.9.1?
Type which ruby to see the path your system thinks ruby is in.
Did you use a --prefix=... option for configure when you set up the configuration? Normally Ruby from source wouldn't be in /usr/local/ruby/bin. The Ruby executable would be in /usr/local/bin/ruby, but that is not how you'd set up your PATH to use it, so that looks suspicious. Notice that your path already contains /usr/local/bin so if Ruby installed into the normal location for a source-installation, that path will pick it up and your final search of /usr/local/bin/ruby will be wrong and unnecessary.
If you installed the gem before you installed the new version of Ruby then the gem would be part of the previous installation, not the current one, and wouldn't be visible to it. They're separate installs.
Unless you are trying to do a system-wide install for multiple users there is no real reason to compile from source and allow it to install to /usr/local/bin. I highly recommend installing RVM, then letting it install any Ruby versions into RVM's ~/.rvm sandbox. Gems will also be installed relative to the currently enabled RVM controlled ruby, which is a really good thing.