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.
Related
I have limited privileges on a shared machine I'm using, so I can't install gems the way I'm used to. For example:
$ gem install request-log-analyzer
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /usr/lib/ruby/gems/1.8 directory.
Is it possible to install a gem locally? (if it matters, I'm trying to install this gem.)
I saw a number of posts on Stack Overflow that talked about using Bundler or gemfiles but I'm not installing this gem for a Ruby on Rails project - I just want to use it in isolation.
I'm running Linux, not sure which flavor though.
You can try:
gem install --user-install gem_name
Add the --local flag to your install:
gem install --local request-log-analyzer
If that causes any problems, try downloading the gem manually and pointing gem directly to it using:
gem install --local path/to/gem/filename.gem
If you want to install it to your user home, as per rubygems:
When you use the --user-install option, RubyGems will install the gems
to a directory inside your home directory, something like
~/.gem/ruby/1.9.1. The commands provided by the gems you installed
will end up in ~/.gem/ruby/1.9.1/bin. For the programs installed there
to be available for you, you need to add ~/.gem/ruby/1.9.1/bin to your
PATH environment variable.
The command for this would just be
gem install --user-install request-log-analyzer
You could just use RVM: Ruby Version Manager. It is a complete version manager, along the lines of node version manager (nvm) and others, in that it allows you to have different versions of ruby and different collections of gems for each project. It does the job of keeping gems isolated from each other as well as from the system ruby, but at the expense of learning a complete version manager.
When run without root, it installs locally in ~/.rvm and doesn't affect other users.
I need to host different Ruby applications on a single server. Applications have mutually-incompatible ruby versions and gems. Is there a way to install RVM in system-wide mode and have gemsets which are also system-wide, and not tied to a specific user and their $HOME directory? Or is there a better approach altogether for hosting different Ruby apps on the same machine?
Use mixed mode installation of RVM basically you get system installation and as every user that should have his own gemsets run:
rvm user gemsets
Because of numerous problems with RVM in system-wide mode (rvmsudo not working, directories being created in filesystem root by RVM, etc.) I've decided to go down the vendor/bundle route.
I installed ruby 1.9.3 w/ latest patches using my distro's package manager and then ran gem install bundler --no-user-install which installed bundler gem system wide.
I then ran in each app's directory bundle install --path vendor/bundle --without development test which installed required production gems in app's vendor/bundle directory. If there were any rake tasks or plain ruby files to run as part of app's setup then those were prefixed with bundle exec ... (which uses the gem environment from vendor/bundle when running the command).
In the end all apps were directly runnable without any prior environment setup or RVM magic, and each have separate gems.
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 installed Ruby and Rails via RVM, but using "gem install something", the console tries to install into /Library/Ruby/Gems/1.8 directory.
Do I still need this Ruby dir?
You are still using the default Ruby. You need to activate RVM for your shell session. See item 2 at the below:
http://beginrescueend.com/rvm/install/
(and no I wouldn't delete the original Ruby dir)
You have to direct your shell to use RVM and the Ruby version. You can do so by issuing the following command:
rvm use *ruby version (example: 1.8.7)*
Or, if you have created a gemset for particular project:
rvm use *ruby version (example: 1.8.7)*#*my_gem_set*
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.