Ubuntu 18.04: failing to install rails after installing ruby with snap - ruby-on-rails

I want to install Rails on my Ubuntu 18.04.
My installed ruby-version was 2.5.1 and since at least v.2.6 is recommended for Rails I uninstalled it like described here
and then installed ruby v2.7 with
sudo snap install ruby --classic
like suggested here
Now ruby -v shows me ruby: 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
Then I run sudo gem install rails which runs without error and tells me that gems are installed.
When I run rails -v I get the message:
Der Befehl 'rails' wurde nicht gefunden, kann aber installiert werden
mit:
sudo apt install ruby-railties
(command 'rails' cound not be found, but can be installed with sudo apt install ruby-railties)
Executing apt install ruby-railties proves to be useless - as expected, since a different package manager is used.
When I run require 'rails' in irb I get a "true".
Question: what am I missing? What am I doing wrong?

First of all ,uninstall all ruby version do you have on your system .
example sudo apt remove ruby
After that install ruby by using snap :
sudo snap install ruby --classic then gem install rails.
Tape this in your terminal whoami ,copy the ouput and
finaly go open bashrc and put this like
alias rails="ruby/home/resultOfOuputOfWhoami/.gem/gems/railties-7.0.0/exe/rails"
That's it ,you got the latest version of rails

Related

Ruby version not same as installed version

I am trying to install Ruby on rails on a Mac Mojave:
$ brew install ruby
Warning: ruby 2.7.1 is already installed and up-to-date
To reinstall 2.7.1, run `brew reinstall ruby`
This shows me that I am running Ruby 2.7.1.
But when I check the version I get:
$ ruby --version
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
This tells me I am using Ruby 2.3.7.
I don't understand.
To run Rails I need >= 2.4.4 apparently:
$ sudo gem install rails
.....................
ERROR: Error installing rails:
zeitwerk requires Ruby version >= 2.4.4.
and
$ which ruby
/usr/local/opt/ruby/bin/ruby
So until I get ruby version to at least 2.4.4 I can't run rails.
Update
Install RVM on MAC as follows
$ brew install gpg
$ curl -L https://get.rvm.io | bash -s stable --autolibs=enabled --ruby
$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
Got these instructions from:
https://null-byte.wonderhowto.com/how-to/mac-for-hackers-install-rvm-maintain-ruby-environments-macos-0174401/
But then I install Rails:
$ sudo gem install rails
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
and so I tried to crate a Rails project:
$ rails new blah
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.
What is going on there? I seem to have successfully installed Rails but cannot create a Rails project.
The output from this command brew install ruby is not telling you that you're running ruby 2.7.1. That just says you already have ruby 2.7.1 installed for brew. But you could have other ruby versions installed in other ways. When you do
ruby -v
ruby executable is looked for in paths listed inside your environment variable PATH, in order. You can see those paths with
echo $PATH
So, managing different versions of ruby is hard and version managers exist for this reason. I suggest you to install rvm

error in uninstalling Ruby from UBUNTU 14.0.4 LTS

I have made some mistake in installing Ruby and and now I'm trying to uninstall it (How to remove ruby from ubuntu) but it's giving the following error. I tried with sudo apt-get purge ruby but still couldn't uninstall. It shows ruby is not installed but I did check and confirm that it is installed in the location /usr/local/bin/ruby. please help me to uninstall Ruby and RVM from my machine.
$ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
$ sudo apt-get purge ruby 1.8.7
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libhdf5-mpich2-1.8.7' for regex '1.8.7'
Note, selecting 'libhdf5-1.8.7' for regex '1.8.7'
Note, selecting 'libghc-utility-ht-prof-0.0.5.1-87764' for regex '1.8.7'
Note, selecting 'libhdf5-openmpi-1.8.7' for regex '1.8.7'
Note, selecting 'libhdf5-serial-1.8.7' for regex '1.8.7'
Note, selecting 'libghc-utility-ht-dev-0.0.5.1-87764' for regex '1.8.7'
Note, selecting 'libghc-utility-ht-dev' instead of 'libghc-utility-ht-dev-0.0.5.1-87764'
Note, selecting 'libghc-utility-ht-prof' instead of 'libghc-utility-ht-prof-0.0.5.1-87764'
Package 'libhdf5-1.8.7' is not installed, so not removed
Package 'libhdf5-serial-1.8.7' is not installed, so not removed
Package 'libhdf5-mpich2-1.8.7' is not installed, so not removed
Package 'libhdf5-openmpi-1.8.7' is not installed, so not removed
Package 'ruby' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 567 not upgraded.
If you are using rvm, then you can uninstall ruby 1.8.7 using the command
rvm unistall 1.8.7
and then you uninstall the rvm using the command
rvm implode
if you want to remove ruby completely,
sudo apt-get purge ruby rubygems
Or you can follow this steps below,
Use this to find out what it is
$ readlink -f /usr/local/bin/ruby
/usr/local/bin/ruby1.8.7
Use this to find out what package is using:
$ dpkg -S /usr/local/bin/ruby1.8.7
ruby1.8: /usr/local/bin/ruby1.8.7
And use this to install,
$ apt-get purge ruby1.8.7
I have removed the ruby directory from home directory and followed the below steps...
$ whereis ruby
ruby: /usr/local/bin/ruby /usr/local/lib/ruby
$ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
$ sudo rm -rf /usr/local/bin/ruby
$ sudo rm -rf /usr/local/lib/ruby
$ ruby -v
bash: /usr/local/bin/ruby: No such file or directory
finally it got uninstalled !!
Thanks to Rick

Rails not installing when following documentation

$ sudo gem install rails
Successfully installed rails-3.1.1
1 gem installed
Installing ri documentation for rails-3.1.1...
Installing RDoc documentation for rails-3.1.1...
This did not properly work, as when I run rails, I get
The program 'rails' is currently not installed. You can install it by typing: sudo apt-get install rails
And doing ruby --version gives
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
and doing which rails returns nothing. Anyone have any ideas about how I would go about installing the latest version of Rails? I've tries using the apt-get method, but I got Rails 2, however I need Rails 3 for my purposes.
I've had the similar problem with my Ubuntu installation.
Solved it following to steps:
Make sure rubygems is installed
created the following symlink:
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

Installed Ruby, but installing RubyGems does not work

I just installed ruby on Ubuntu by running this command:
sudo apt-get install ruby1.9.1-full
Then I downloaded RubyGems, extracted it, and navigated to that directory. When I typed this command:
ruby setup.rb or sudo ruby setup.rb
I got this error:
The program 'ruby' is currently not installed. You can install it by typing:
sudo apt-get install ruby
How should I invoke my Ruby installation? Should I reboot? Any ideas what the problem is?
I think your problem is twofold:
Ruby1.9 bundles rubygems by default so there is no need to install manually.
Ruby will proabably be installed as ruby1.9.1-full and you might need to rename manually to ruby. A good solution is to use rvm.
Use:
sudo ruby1.9.1 setup.rb
or
sudo ruby1.9.1-full setup.rb

Can I install gems with apt-get on Ubuntu?

I am new to Ruby and just diving in. The Ruby tutorial says I should get the packaging system from here: http://rubyforge.org/frs/?group_id=126
I am on Ubuntu Linux. The page has a .tar and a .gem option for downloading. Which should I download?
Also, are gems exactly analogous to Java jars? And why do I need the gem packaging system if I can just download gems one by one as they are needed?
Ubuntu now have rubygems as a package
For Ubuntu 12:
sudo apt-get install rubygems
For Ubuntu 14.04:
sudo apt-get install rubygems-integration
On Ubuntu 16.04 and Ubuntu 18.04, both sudo apt-get install rubygems and sudo apt-get install rubygems-integration failed for me. Instead, I had to do this:
sudo apt-get install ruby-dev
If on Ubuntu 14.04 try below
sudo apt-get install rubygems-integration
First, download *.tar file, unpack this file, then go to rubygems directory in your console, and type
ruby setup.rb
That's it :)
If you install the full ruby application set with
sudo apt-get install ruby-full
You will get gems and much more by default. Tested on Ubuntu 16, it could also work on other version.
For me in Ubuntu 20.04 I did 3 things to create a new Ruby and Rails app.
Install Ruby development version
sudo apt install ruby-dev
Install rails from gem
sudo gem install rails
Create new application
rails new blog
I got error while installing rails(sudo apt install rails) only, So I installed devlopment version. I got permission related error while not using Sudo as well while installing gems and rails.
For Ubuntu
First install ruby:
sudo apt install ruby
Note that : sudo snap install ruby will throw this error :
error: This revision of snap "ruby" was published using classic
confinement and
thus may perform arbitrary system changes outside of the security
sandbox that snaps are usually confined to, which may put your system at
risk.
If you understand and want to proceed repeat the command including
--classic.
Finally, download latest tar version of ruby gems here:
https://rubygems.org/pages/download
Unzip and cd to the folder and finally type in terminal:
sudo ruby setup.rb

Resources