Install rails from gem - ruby-on-rails

I installed ruby and next rails as a gem with this command
gem install rails -include-dependencies
It installed successfully but even after restarting my command window i couldnt run commands like:
rails
or
rails s
My question is what do i have to add to my path so that rails is recognized in my command windwo?
----Update----
I ran gem list but rails isnt listed,
so i will reune the gem install rails command

If you are using rvm you need to use the gemset of RVM in which you have installed your rails gem.
cmd for the same is
rvm gemset list
will list the gemset persent in your version manager, later select the gemset with following command:
rvm gemset use [gemset_name]
hope am redirecting you in the right direction.

Try creating a project with:
rails new whatever
Go into the project:
cd whatever
Install dependencies:
bundle install
Start server:
rails s

If you use a unix based OS, you may need to get the path of the rails executable into your $PATH e.g. by e.g. exec $SHELL -l.

Apologies if you know about this already, but why don't you use a pre-packaged installer like RailsInstaller?

Are you using rbenv?
If so, try running this in your terminal:
rbenv rehash

Since you are using windows, you might not have added Ruby's bin directory in path :
To add path in windows :
Right click My Computer >> properties >> Adavced System Settings
Then edit the path variable in User Variable and just add the path of your installed Ruby's bin directory.
Open a new command prompt to get the path changes.

Related

Using rvm bundle install doesn't install rails

I'm freshly using rvm for running a legacy project.
I installed rvm fine. Running which ruby gives the correct rvm version:
/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin/ruby
Then running which bundle, also indicates that bundle is using the correct rvm version:
/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin/ruby
Now to get my project running, I run bundle install. It's important to stress on the fact that in my Gemfile I have
gem 'rails', '5.0.7'
Running rails s after those steps, gives:
Rails is not currently installed on this system. To get the latest version, simply type:
Running which rails gives:
/usr/bin/rails
implying that the system version and not the rvm version is being used.
echo $PATH shows:
/Users/Mahmoud/.rvm/gems/ruby-2.5.5/bin:/Users/Mahmoud/.rvm/gems/ruby-2.5.5#global/bin:/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin:/Users/Mahmoud/.rvm/bin:/Users/Mahmoud/.pyenv/versions/3.7.2/bin:/usr/local/bin:/Users/Mahmoud/.pyenv/bin:/usr/local/opt/openssl#3/bin:/usr/local/opt/openssl#3/bin:/usr/local/opt/libxml2/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/MacGPG2/bin:/Library/Apple/usr/bin:/Users/Mahmoud/.ebcli-virtual-env/executables:/usr/local/mysql/bin
My question is, why hasn't rails been installed when I used bundle install? And why is which rails refering to my system and not my rbenv path?
I'll bet your RVM isn't set up correctly and /usr/bin/ appears in your PATH before RVM's bin directory. Run echo $PATH to confirm.
If so, back up your dotfiles for safety and run rvm get head --auto and it should put your PATH right. Logout and log back in or source your dotfiles (source ~/.bash_profile or whatever) and try again.

Error on Rails S | Rails Server

I'm a newbie in rails. I installed Rails(4) and Ruby using RVM.
I get an error whenever I run rails s or rails server on a different terminal.
It says
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
It only works on the first terminal I used to install rails on.
The left terminal is the one where i installed rails on
It looks like you havent added the rvm path in bashrc or bash_profile
/home/username/.bashrc
/home/username/.bash_profile
Add
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
and
source .bashrc
Your terminal likely isn't set to be a login terminal, so RVM isn't being setup correctly on new terminal instances.
See https://rvm.io/integration/gnome-terminal for how to configure your terminal as a login terminal.
Are you using gemsets? You can think of each gemset as an independent, compartmentalized "environment" that houses your rails installations.
If you've already installed rails under a gemset, are you making sure your new terminal window's environment is using the gemset that you installed rails on? When you open a new terminal window, it won't know which gemset to use, unless you configure it to use some default gemset. You can use the gemset you created by doing:
$ rvm use <YOUR_GEMSETNAME>
If you don't know/remember what gemsets you created, you can list them with the following command. Try using this command on the terminal that worked. It'll indicate which gemset you're using (then you can use that gemset name with the use command above):
$ rvm gemset list_all
This Rails tutorial does a good job of giving step by step instructions on installing ruby and rails with rvm properly. Just remember that with every new terminal that you open, you have to make sure you're using that gemset.

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.

Setting path for rails 3.2.8 in Ubuntu 12.10

I am completely new to Ubuntu, I am trying to complete my installation of Ruby On Rails, so far I have installed both Ruby 1.9.3 and set it as the default and I installed Rails 3.2.8, when I open a new terminal it doesn't recognise my Rails install and I understand from looking for help that I need to set a path in a bashrc file.
2 problems I have is trying to understand what my path is and how I input this to the bashrc file(how can I find the file or do I use a command in the terminal to do set the path)
Here is the location of my Ruby and Rails install
andrew#andrew-laptop:~$ sudo updatedb
[sudo] password for andrew:
andrew#andrew-laptop:~$ locate rails|grep -e "bin/rails$"
/home/andrew/.rvm/gems/ruby-1.9.3-p286/bin/rails
/home/andrew/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/bin/rails
I tried this but nothing changed
andrew#andrew-laptop:~$ export PATH=$PATH:/home/andrew/.rvm/gems/ruby-1.9.3-p286/bin
You are on ubuntu so most likely this steps should fix:
https://rvm.io/integration/gnome-terminal/
close and open new terminal window
rvm use 1.9.3 --default --install
gem install rails
visit https://rvm.io for more details

How do you configure RadRails to use Rails installed through RVM?

How do I properly setup Aptana RadRails if I've installed Rails through RVM?
I followed the install on http://railstutorial.org/ but my script paths don't work: e.g.:
'rails' path: /home/marius/.rvm/gems/ruby-1.8.7-p302#rails3gemset/bin/rails
Detected path: Not Detected
After installing ruby through rvm, I was able to get eclipse to use that install by:
In Eclipse, go to Window -> Preferences.
In the Ruby/Interpreters tab click "Search"
For me this found all of the ruby installs from rvm, and it added them to the interpreters list. I edited the "Name" field to include the version number for convenience.
try to run this in the command line. It will show you real path to the available rail script for current environment.
$ which rails
In Aptana Studio 3 (build: 3.0.8.201201201658) there is no Window -> preferences. If you have a .rvmrc in your project work directory, stating for instance:
rvm use ruby-1.9.3-p0#mygemset
... then Aptana should pick up the correct environment; in this case using ruby-1.9.3-p0 with gemset mygemset. Don't forget to run build install or build update (when you updated your Gemfile) from your project working directory path.
I must add that Aptana Studio 3 seems a bit buggy when it comes to picking up the correct environment, especially when trying to use ruby-debug-ide19.
Did you try with just /home/marius/.rvm/gems/ruby-1.8.7-p302/bin/rails ?
You have to run eclipse/aptana from a terminal session.
Without RVM :
Please type command whereis ruby in console.
you will get the path like /usr/bin/ruby or /usr/local/bin/ruby to check which is correct interpreter path /usr/bin/ruby -v if you get version. that is your interpreter.
With RVM :
Please type command: rvm info
binaries:
ruby: "/home/<USERNAME>/.rvm/rubies/ruby-2.0.0-p247/bin/ruby"
copy this path and paste wherever you need enter you interpreter path.
It worked for me. and I hope it will help others as well.
Cheers!

Resources