Ruby/Rails is contradicting itself, what should I do? - ruby-on-rails

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 .

Related

How To Remove Rails Installation From /usr/bin/rails

I'm trying to install Ruby on Rails on MacOS Mojave. Here's what I have so far:
ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
rails -v
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.
which rails
usr/bin/rails
I've done some research on the issue and it looks like because I used sudo when I originally ran gem install rails, the rails executable got put in a location where it doesn't have access to the right libraries.
How do I fix this or remove the rails executable to start a fresh install from scratch?
Ignore the existing Rails installation in your system Ruby. Don't bother mucking about with any changes you've made to system Ruby and its gems. Just put it in the past and move on:
Install RVM with:
\curl -sSL https://get.rvm.io | bash -s stable
Restart your shell, then install Ruby with:
rvm install 2.6.5
Don't use system Ruby.
Then install Rails (without sudo, never use sudo with Ruby installed by RVM):
gem install rails

What is appropriate way to install ruby on Ubuntu 14.04

I have a computer serves as a server. I have bitnami-gitlab stack on it. And now I want to install my rails app to this server. The thing confuses me, bitnami-gitlab has ruby interpreter and other apps (rails , gem, bundler etc.). Gitlab application uses git user on ubuntu. When I type;
sudo su git
which ruby
It gives me the directory of ruby which is inside of bitnami installation directory. Now, I want to install ruby, rails, apache and passenger to deploy my rails app. What is the appropriate way to do? I want to start my rails app as boot time. Should I install ruby to root user or my own user?
When I install ruby, will my gitlab application crahs?
Here is how I do it >
First, update apt-get:
sudo apt-get update
Then if you do not have it install Curl, for installing RVM
sudo apt-get install curl
Then run the appropriate RVM install there are multiple options like added rails, puma JRuby etc. check RVM website for more info. For just ruby run >
\curl -L https://get.rvm.io | bash -s stable
Now exit the shell session and start a new one
source ~/.rvm/scripts/rvm
RVM has its own requirements that can be auto installed by running >
rvm requirements
Now managing you ruby environments is easy and you can have multiple versions without making a mess.
To install any ruby version you need just run (x.x.x) version of the ruby>
rvm install x.x.x
To list versions you have installed run >
rvm list
Note also that now you can specify in your GEMFILE what version to use. Simply add ruby 'x.x.x' and rvm uses the version you specified as long as its already installed. Not having it raises error.

Unable to use GEM_HOME in radrails

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

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

Can't install rails - "File exists # dir_s_mkdir" error

I have had rails installed and almost working. Was working on a solution to another problem with I accidentally closed the bash window. So I reopened it, and now I am unable to use rails at all and it's telling me that rails isn't installed. So I ran gem install rails --no-ri --no-rdocand now I get the following:
ERROR: While executing gem ... (Errno::EEXIST)
File exists # dir_s_mkdir - /usr/local/Cellar/ruby/2.1.1_1/lib/ruby/gems`
How do I correct this error?
I just removed the broken gems, site_ruby and vendor_ruby symlinks from the /usr/local/Cellar/ruby/2.1.1_1/lib/ruby/ folder and now everything seems to work fine.
I just added a gems/ directory here /usr/local/lib/ruby/ and that solved the issue.
for a temporary solution, you can mkdir -p /usr/local/Cellar/ruby/2.1.1_1/lib/ruby/gems/2.1.0 to solve.
When you open your bash window (called the "terminal window" or "console"), what folder ("directory") are you in? Find out with:
$ pwd
Navigate to the folder where you created your Rails project using the Unix cd command, for example:
$ cd workspace/learn-rails
If you are using RVM, make sure you have selected the correct gemset:
$ rvm gemset list
gemsets for ruby-2.1.1 (found in ...)
(default)
global
=> learn-rails
Then see if Ruby and Rails are installed:
$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
$ rails -v
Rails 4.1.0
Refer to the article Install Ruby on Rails for help. If you haven't followed all the steps in the article, you may have problems, especially if you followed some of the inaccurate instructions found elsewhere on the web.
I was recently in this wormhole. It seems like Homebrew's ruby installation has an issue with soft links and uses version 2.1.1. I couldn't "gem install" anything without getting the annoying "File exists # dir_s_mkdir" error. Even tried MacPort and that was a nightmare.
First uninstall ruby via
brew uninstall ruby
or
port uninstall ruby
And follow the instruction on https://rvm.io/rvm/install to install ruby
\curl -sSL https://get.rvm.io | bash -s stable --ruby
It might then complain about ruby-2.0.0-p353 not installed
To install do:
rvm install ruby-2.0.0-p353
Then run the rvm install script. Your "gem install << whatever >>" should now work
This fixed the issue for me (Homebrew on a Mac, Ruby 2.1.3):
$ brew reinstall ruby
$ brew unlink ruby && brew link ruby
the same issue. I just remove dir_s_mkdir, then pod install. it works for me!

Resources