Beginning Ruby on Rails in Linux Mint - ruby-on-rails

This may sound very basic to many of you. I have just started a Ruby on Rails tutorial in Linux. I'm very new to the Linux OS. I have installed a rvm. But I am unable to install Rails. It's saying "cant load such file --zlib". And I can see two source files for Ruby. Not sure if I have two Ruby installed.

Just take a note that you have selected the correct build system:
"Tools -> Build System -> Ruby"
Then press CTRL+B.
This should work.

You can execute .rb file in sublime using ctrl + b.

It seems you are a bit confused about how Ruby on Rails work.
Sumblime can run your ruby code but not on Rails stack.
My suggestion it's to work always with an open terminal on the directory of your rails application.
Let's assume you created a new rails project as
rails new helloWorld
The rails generetor will create a subfolder helloWorld.This will be your working directory in the terminal.
So you have to do:
cd helloWorld
and then
rails s
It will run your rails application on an embedded server on localhost:3000 by default.

What method did you use to install ruby?
If you compiled from source you may need to do
sudo apt-get install libssl-dev
And then recompile ruby
Otherwise, you may not have the most recent version of Rubygems
Try:
go to https://github.com/rubygems/rubygems/releases/tag/v2.2.3
download rubygems-update-2.2.3.gem
call the directory where the file was dl'ed, then
gem install rubygems-update-2.2.3.gem
update_rubygems --no-ri --no-rdoc
rubygems --version #Should show 2.2.3
gem install rails

Related

Error trying to bundle install a ruby new generated project

I just started in Ruby, so after a lookup on internet I installed it using rvm. The version of ruby is 2.6.3. This is the output for ruby -v:
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
I also installed Rails using gem install rails and get the version 6.0.2.1.
After that I created a project called blog using rails new blog, the project was created and in the directory I run bundle install and get the following error message:
There was an error while trying to write to
`/home/ramon/.bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47/versions`.
It is likely that you need to grant write permissions for that path.
After that I run sudo bundle install and get this error:
Your Ruby version is 2.7.0, but your Gemfile specified 2.6.3
But my Ruby version is already 2.6.3.
After searching for answers on internet I tried these solutions:
sudo gem update bundler
sudo gem install bundler
sudo gem install rails
But all of this returned the same error:
/usr/bin/env: ‘ruby’: No such file or directory
Then I run which ruby and got this: /home/ramon/.rvm/rubies/ruby-2.7.0/bin/ruby
and added this line do .bashrc:
export PATH=$PATH:/home/ramon/.rvm/rubies/ruby-2.7.0/bin/ruby
But still got the error.
I tried changing this line in /etc/login.defs to:
ENV_PATH PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/$
And /etc/environment to:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/$
But I dont know what to do anymore, tried every solution on internet and nothing works.
One thing I tried was running which ruby as superuser, and I got nothing.
Maybe it is a PATH problem or a permission problem. But I dont know anymore what to do.
I use lubuntu 19.04.
I think you have two versions of Ruby , so you may try this:
rvm --default use [correct version number]
Create a new file .ruby-version in the main folder of project and put ruby version inside:
2.6.3
or
2.7.0
because I don't know which Ruby version you want do use.
Save and go to the console and do this:
cd ..
cd blog (your project name)

Rails Server is not starting on Windows 10

I am using windows 10. I install Rails and other supporting software via railsinstaller.org website.
Now I go on CMD and writing command rails server but Rails server not starting work. when I open link in firefox http://localhost:3000
Following is snapshot of output when I write rails s in cmd. I have Rails 4.2.5.1 in my PC and using Windows 10
The problem my be caused due to following (Unable to Install gems)
if you are using latest version of ruby installer to install ruby then there are problem for installing nokogiri and ulifier or other gem which needs to compailing in your pc. so you needs to install devkit first. For this please do following:
The download is a self-extracting archive. When you execute the file, it’ll ask you for a destination for the files. Enter a path that has no spaces in it. We recommend something simple, like C:\RubyDevKit\. Click Extract and wait until the process is finished.
Download from here
Next, you need to initialize the DevKit and bind it to your Ruby installation. Open your favorite command line tool and navigate to the folder you extracted the DevKit into.
cd C:\RubyDevKit
Auto-detect Ruby installations and add them to a configuration file for the next step.
ruby dk.rb init
Install the DevKit, binding it to your Ruby installation.
ruby dk.rb install
Now run bundle install
If still problem persist downgrade your ruby or install linux distro.
You need to change your directory to the app root folder.For Example if your app name is 'myapp', then type cd myapp and run rails server with rails s.
Check if the bin/rails file is in place. If not, generate a new sample app, then copy the bin folder to it.
simply add gem "tzinfo-data" to your Gemfile and run bundle install and you are good to goenter image description here

Rails - Closed terminal and rebooted machine - now bash tells me rails isn't installed

Running OSX Mavericks, ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0], rvm 1.25.23 (master), and rails-4.1.0 (allegedly)
I'm working through the railsapps.org book on learning rails and made it about 1/2 way through yesterday. When I stopped for the day, I closed out iTerm2 and shut off the Macbook Pro. Today, I powered up, opened iTerm, navigated to my working directory (~/rubyonrails/learn-ruby) and entered rails -v.
I see this:
`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.`
So I run sudo gem install rails and it shows that it has installed rails-4.1.0. Now rails -v still gives me the same error message above.
I tried also running rvm use ruby-2.1.1#learn-rails first and I still get the error message.
So I'm a little stuck and I can't figure out what to do to get rails working. Also, how do I go about setting up the bash environment such that I don't have to go through this each time? It would be nice to nav to my working directory and just start work without having to do a bunch of re-installation and reconfiguration each time.
Regards,
Jeff
please type in your shell:
$ bash --login
and then repeat your commands.
rails -v
Also try to call it with the full path:
like:
/your/path/to/rails -v
I think that the shell just doesn't know where rvm/rails etc is located.
You can solve this by entering:
$ source ~/.rvm/scripts/rvm
When you switch to the ruby-2.1.1#learn-rails ruby/gemset combo, and do gem list, what do you see?
The way people usually use rvm is to have every project folder specify the ruby & gemset it uses (they don't all have to be different). This is done with files called .ruby-version and .ruby-gemset. These should contain, in your case, ruby-2.1.1 and learn-rails respectively.
Set these if you haven't already, then leave the folder and enter it again. Then do bundle install to install the gems for the project into the rvm/gemset combo.
Your problem is that you ran
sudo gem install rails
The error message telling you to do this comes from your system Ruby, which doesn't know that you want to use RVM.
RVM installs gems into your user-space directory. By using sudo, you're bypassing this and installing it into (effectively) the superuser space, i.e. globally.
If you instead just run
gem install rails
then you'll be using RVM's copy of the gem utility rather than the globally installed version.

Do I have to install Rails on every new project?

This is a beginner-level question.
I'm using Ubuntu 12.04
I copied a project (created on Rails 4 using the rails new command) from Dropbox to my local environment, where I have previously install Rails 4 and up-to-date Ruby and RVM, went to project's directory, typed rails server and got
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
I ran gem install rails instead.
Will I have to run gem install rails on every project's directory? I thought the Rails install was a general and accessible on my whole environment.
The project was created using the same Ruby version, but on a MacOS X system.
The project is a static web brochure and has no database configuration.
Thank you in advance.
Make sure you're using the correct version of Ruby - the same version that you'd installed Rails into - with rvm list.
You likely have two of them (since you have such an issue) - the system Ruby and the RVM-installed Ruby. And likely RVM didn't engage and hook up the correct path to the rails executable, thus the error.
This should fix the issue:
rvm use whatever-ruby-you-had-installed-rails-into
Where whatever-ruby-you-had-installed-rails-into is a string like ruby-2.1.0-p0 taken from the rvm list output.
To make RVM retain Ruby version for the project.
echo whatever-ruby-you-had-installed-into >.ruby-version
in your project's path.
So after a few hours of testing, reproducing the problem, and reading (the other answers inclusive) I got the solution as follows:
Short answer: No. Rails needs to be installed only once.
Long answer: This problem occurred because of a default setting on Terminal that prevents the system from using RVM installations of ruby and rails. The solution is to integrate RVM with gnome-terminal as described in the RVM website.
With terminal window active, go to the menu at the top bar
Edit > Profile Preferences > Title and Command tab
Check the Run command as a login shell box
Restart Terminal and make sure your gemset and ruby version are set
rails server should now work as expected (you might be prompted to run bundle install before Rails can actually run fine, follow the promtp).
I am still learning to work with Ruby on Rails, so any inputs, clarifications, or additional information on the issue is more than welcome.
You don't have to install Rails on every project, but the gems that you need for that project.
With bundle install you install all the gems that you specify in Gemfile.
If you want to avoid reinstall the gems every time you change project, I suggest you to have a better look to RVM: it has got an opt called gemset (https://rvm.io/gemsets), if you use it you just need to switch your gemset:
rvm gemset use yourgemset
I hope it can help you.

How to run or setup rails3?

Have 2 ruby installations 1.8 and 1.9.1, have 2 gems. From "gem1.9.1 install rails" installed rails3 to my system, but don't have "rails" in my "path".
How can i get rails to launch from entering rails in terminal?
EDIT
removed all ruby and ruby-gems from my system (Ubuntu 10.10) and installed ruby1.9.1 - it came with gems1.9.1 and then installed
gem1.9.1 install rails
How do i make "rails" run the installed gem rails?
EDIT 2
Found it!
The rails was installed in /var/lib/gems/1.9.1/bin/rails
just had to add a alias "rails" to it in system $PATH
How did you install your rubies? I'd strongly suggest to use a version manager like rvm, otherwise you're asking for trouble.
You should be specific about your system environment. In windows when you install ruby, you just have RUBY_HOME/bin in your path. Whenever you install rails by gem install rails , it automatically deploy executable files in RUBY_HOME/bin folder. So that you can directly execute that command.

Resources