Unable to use GEM_HOME in radrails - ruby-on-rails

I have setup Radrails on my linux machine. I dont have root privileges on this machine and I also cant edit the ruby installation folder. I have set GEM_HOME and GEM_PATH to a location where I have privileges. I am running radrails from the terminal where I have set these variables. Does Radrails is recognize the gem location?
Also I am not able to start the Webrick server using Radrails. The server always is in stopped state and the console output is blank. I am not able to fix this since I dont see any errors.
thank you!

Use rvm or rbenv to change ruby and gem space to another one. If you will begin usage of the them do the following:
Install rvm with ruby:
$ \curl -sSL https://get.rvm.io | bash -s stable --ruby
or install rbenv, and then install ruby, and make it global:
$ \curl https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash
$ rbenv install 2.1.4
$ rbenv global 2.1.4
Install the rails without documentation into the general gem space:
$ gem install rails --no-ri --no-rdoc
Enter to the project, create two files .ruby-version with just installed version of ruby (in example 2.1.4), and .ruby-gemset with name of your project:
$ cd project-folder
$ echo "2.1.4" > .ruby-version
$ echo "your-project-name" .ruby-gemset
Fix Gemfile with newly intsalled version of ruby adding a line:
ruby '2.1.4'
Reenter to the project folder, and rvm will generate its wrappers:
$ cd .. ; cd project-folder
Issue gem installation:
$ bundle install

Related

Ruby/Rails is contradicting itself, what should I do?

I am trying to learn Ruby on Rails, I have installed Ruby, ruby -v gives ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18] and I have installed rails using gem install rails however when I run rails -v I get the following dialogue.
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
I then do as the prompt asks and run sudo gem install rails (inputting my pw) which gives me;
Successfully installed rails-6.0.2.2
Parsing documentation for rails-6.0.2.2
Done installing documentation for rails after 0 seconds
1 gem installed
to check that Rails has installed properly I run rails -v again, and again I get;
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
Am I missing something very obvious?
The best way to manage your Ruby/Rails environment is to use a tool like rvm and never use the system Ruby/Rails. Changing Ruby/Rails versions globally for all your apps will most likely break them, so you want each app to be locked to a specific Ruby/Rails version and only upgrade each one manually.
Start by installing RVM locally for your user:
\curl -sSL https://get.rvm.io | bash -s stable --ruby
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
source $HOME/.rvm/scripts/rvm
Make a directory for your app.
mkdir my_rails_app && cd my_rails_app
Make a local .ruby-version and .ruby-gemset for each project:
echo 2.6.5 > .ruby-version
echo my_rails_app > .ruby-gemset
rvm reload
Then install rails only for the specific gemset "my_rails_app" (I usually give each app its own gemset).
gem install rails
rails new my_rails_app .

rails new <app-name> requires password for gems installation in ./vendor/bundle

Your user account isn't allowed to install to the system RubyGems.
You can cancel this installation and run:
bundle install --path vendor/bundle
to install the gems into ./vendor/bundle/, or you can enter your password
and install the bundled gems to RubyGems using sudo.
Password:
If it says that you don't have the priviliges, then you just need to run it with sudo
sudo gem install bundler --no-rdoc --no-ri
but I really recommend installing rbenv or rvm, to have a better control of the ruby versions and with that you don't need password or sudo command to install the gems.
I will guide you to install rvm here, this is for personal preference, but you con install rvenb too with the same result.
before anything else, you have to remove completely the ruby version that you have installed on this moment and all the gems
gem uninstall --all # maybe you will need sudo here
sudo apt-get purge ruby
first install mpapis public key
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
then install rvm
\curl -sSL https://get.rvm.io | bash
then add to .bashrc
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
add to .bash_profile
source ~/.profile
then you can install the ruby version that you want (i am using 2.3.0 here as an example, change for the version that you were working before on the app)
rvm install 2.3.0
with this you have installed ruby, I recommend to run this command if you would not use the documentation of gems in local
echo 'gem: --no-document' >> ~/.gemrc
then you can set the ruby version that you want to use, you have different options, select it manually everyime you open the terminal with
rvm use 2.3.0 # or the version that you want to use in that moment
or add to the gemfile the ruby version and rvm will select if for you everytime you make a cd to the path of the app adding this to your gemfile
source 'https://rubygems.org' # this is by default on your gemfile
ruby '2.3.0' # this is the line you need to add, change for the version that you want on he app
when you have the selected version of ruby, you have to install bundler gem, you need to run this just once by ruby version that you install
gem install bundle
then you can run bundle install on your app and will work like a charm.
With rvm you can have different versions of ruby on rails installed on your machine, an as I said, per version that you install you need to install the bundler gem once.
if you have differents version of ruby installed, I recommend that you add a default so if you haven't set the ruby version on the terminal in that session, it will take one by default, you can do it like this
rvm --default use 2.3.0
hope that this helps you to be clear.

rails rbenv: rails: command not found

I have recently moved from RVM to Rbenv and when attempting to execute rails I am getting an error like the one below
Pauls-Air:~ $ rails
rbenv: rails: command not found
The `rails' command exists in these Ruby versions:
2.1.2
After installing a gem via the command line in a ruby version you have to execute rbenv rehash as described in the docs here and here
For example:
$ rbenv install 2.2.0
$ gem install bundler
$ rbenv rehash
$ gem install rails
$ rbenv rehash
You need to install Rails for each Ruby version within rbenv. Try running rbenv version, I might expect that 2.1.2 is not the ruby version in use for the current project (local version) or maybe your global version.
I ran into the same issue, but none of these other solutions (or any of the others I found elsewhere) worked. I was about to go back to RVM, so I decided to get rid of rbenv completely and it paved the way to the solution.
Try the following - it worked for me:
uninstalling rbenv, remove all references rbenv in your bash profile, and remove the remaining rbenv file folder and its contents.
Reinstall rbenv with homebrew.
Add it back to your bash profile:
export PATH="$HOME/.rbenv/bin:/usr/local/bin:$PATH"
eval "$(rbenv init -)"
Restart the shell:
exec $SHELL -l
Check the path:
echo $PATH
Install Rails:
gem install rails
rbenv rehash
Note: I consulted this for part of this answer: https://www.codementor.io/tips/3732499178/solution-for-rbenv-rails-is-not-currently-installed-on-this-system-to-get-the-latest-version-simply-type
Try to set up your environment with 2.1.2 version running this command line in your terminal:
$ rbenv shell 2.1.2
It works to me
Ensure that the .ruby-version file in your project's directory contains the same ruby version as the one you installed with rbenv.
For me, I set up my environment with the listed "The `rails' command exists in these Ruby versions".
$ rbenv shell 2.1.2
$ rails -v
It works.
Like for example if you want to install Ruby 2.5.3 with Rails 6
follow this way:-rbenv global 2.5.3
$ gem update --system
$ rbenv install 2.5.3
$ rbenv global 2.5.3
$ gem install rails -v 6.0.2.2
$ ruby -v
$ rails -v
The problem is that your global ruby version doesn't match your installed somewhere locally version which is 2.1.2. Try executing anywhere in bash shell:
rbenv global 2.1.2
That way rails will be found by rbenv in your $HOME directory and anywhere else.
rbenv global
Sets the global version of Ruby to be used in all shells by writing
the version name to the ~/.rbenv/version file. This version can be
overridden by an application-specific .ruby-version file, or by
setting the RBENV_VERSION environment variable.

Rails server not running after updating to ruby 2.1.4

I was using rails 4.1.7 with ruby 2.0.0 and have developed an application.
Recently upgraded to ruby 2.1.4 and made that as "Local" setting using rbenv. Now after doing "gem install rails", everything installed well.
Question is now if I try to run server, i am getting error
"Could not find rake-10.4.0 in any of the sources
Run bundle install to install missing gems."
bundle show rake reveals that its installed under
"bundle show rake
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.0"
Shouldn't this be under 2.1.4?
Use rvm or rbenv to change ruby and gem space to another one. If you will begin usage of the them do the following (NOTE: If you already use one of them, just begin with point 2):
Install rvm with ruby:
$ \curl -sSL https://get.rvm.io | bash -s stable --ruby
or install rbenv, and then install ruby, and make it global:
$ \curl https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash
$ rbenv install 2.1.4
$ rbenv global 2.1.4
Enter to the project, create two files .ruby-version with just installed version of ruby (in example 2.1.4), and .ruby-gemset with name of your project:
$ cd project-folder
$ echo "2.1.4" > .ruby-version
$ echo "your-project-name" .ruby-gemset
Fix Gemfile with newly intsalled version of ruby adding a line:
ruby '2.1.4'
Reenter to the project folder, and rvm will generate its wrappers:
$ cd .. ; cd project-folder
Issue gem installation:
$ bundle install

Ubuntu Installation Error

I had used below mentioned commands to install rails in ubuntu 12.10
sudo apt-get update
sudo apt-get install curl
\curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm requirements
rvm install 1.9.3
rvm use 1.9.3 --default
rvm rubygems current
gem install rails
Every steps are doing good, but it works for terminal which we are installing rails. If we exit from the terminal and work on a new terminal then the following error occurs.
The program 'rails' can be found in the following packages: * rails * ruby-railties-3.2 Try: sudo apt-get install
I came through a solution that whenever I open an terminal I would run these cmd
source ~/.rvm/scripts/rvm rvm --default use 1.9.3-p374
Can any one explain why these things happen??
Did you include the init script into your bash_profile/bashrc?
RVM installed by Ruby not working?
I've installed Rails 3.2.9 on my machine with RVM. You can follow this steps:
Install RVM : \curl -L https://get.rvm.io | bash -s stable
Reload shell configuration & test: source ~/.rvm/scripts/rvm
Install Ruby via RVM: rvm install 1.9.2 or rvm install 1.9.3
Choose version Ruby after install: rvm use 1.9.2 or rvm use 1.9.3
Ruby 1.9.2 and 1.9.3 support gem 1.8.25, so you'll install rails: gem install rails -v 3.2.9.
Done.
Note
Reload shell: source ~/.rvm/scripts/rvm and choose version Ruby rvm use 1.9.2 before work with projects.

Resources