0

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.

undur_gongor
  • 15,657
  • 5
  • 63
  • 75
raj
  • 5,989
  • 7
  • 30
  • 62
  • is it rails project to print hello world on web or just ruby code to print hello world ? – Abdul Baig May 11 '15 at 12:50
  • yes.. hello world on web – raj May 11 '15 at 13:02
  • just open up terminal `(ALT+CTRL+T)` change directory to your project `cd path/to/project` , and do `rails s` – Abdul Baig May 11 '15 at 13:04
  • raj@raj-Inspiron-N5010 ~/Desktop/ruby $ rails s /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- rails/cli (LoadError) from /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /usr/bin/rails:9:in `
    ' got this error
    – raj May 11 '15 at 13:11
  • see these http://stackoverflow.com/questions/16326439/rails-4-0-install-error-require-cannot-load-such-file-active-support-loade http://stackoverflow.com/questions/24452652/ruby-on-rails-error-making-new-app-rb55in-require posts – Abdul Baig May 11 '15 at 13:13

4 Answers4

2

Just take a note that you have selected the correct build system:

"Tools -> Build System -> Ruby"

Then press CTRL+B. This should work.

kartik
  • 666
  • 5
  • 21
  • thanks.. i did that and ran the file.. but giving an error /home/raj/Desktop/ruby/rails.rb:1:in `
    ': undefined local variable or method `helloworld' for main:Object (NameError) [Finished in 0.1s with exit code 1] [shell_cmd: ruby "/home/raj/Desktop/ruby/rails.rb"] [dir: /home/raj/Desktop/ruby] [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/raj/.rvm/bin] do i hav to be careful about the location of my file?
    – raj May 11 '15 at 13:04
0

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

rick
  • 1,675
  • 3
  • 15
  • 28
  • rails new hello is giving me an error.. /home/raj/Desktop/ruby/rails.rb:1:in `
    ': undefined local variable or method `helloworld' for main:Object (NameError) [Finished in 0.1s with exit code 1] [shell_cmd: ruby "/home/raj/Desktop/ruby/rails.rb"] [dir: /home/raj/Desktop/ruby] [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/raj/.rvm/bin] do i have to be careful about where i create my file?
    – raj May 11 '15 at 13:03
  • Will you please show your code ? or you can ask new question for this error. – rick May 11 '15 at 13:06
  • This `rails new helloworld` command uses for create new rails application with `helloworld` name and you should execute this in command prompt or terminal. Please go through the official website of rails and get some knowledge that how to create new basic rails application and move forward. http://guides.rubyonrails.org/getting_started.html – rick May 11 '15 at 13:12
  • it seems rails is not properly installed. i am unable to install using gem install rails.. gives the following error ERROR: Loading command: install (LoadError) cannot load such file -- zlib ERROR: While executing gem ... (NoMethodError) undefined method `invoke_with_build_args' for nil:NilClass – raj May 11 '15 at 13:55
0

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.

  • it seems rails is not properly installed. when i rub rails --version,i get the following error.. i am unable use gem install rails.. /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- rails/cli (LoadError) – raj May 11 '15 at 13:52
  • gem install rails give error ERROR: Loading command: install (LoadError) cannot load such file -- zlib ERROR: While executing gem ... (NoMethodError) undefined method `invoke_with_build_args' for nil:NilClass – raj May 11 '15 at 13:55
0

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
  • The first half of this solution came from http://stackoverflow.com/questions/26947586/installing-rails-with-gem-error-loading-command-install-undefined-method-in – Evan Schwartz May 11 '15 at 14:46
  • Alternatively, [this video](https://www.youtube.com/watch?v=1d6rnWRb_7k&list=PLDmvslp_VR0xlwr5lAx2PDsZLu7oIOhpX&index=4) walks you through installing rails on linux – Evan Schwartz May 11 '15 at 14:52
  • the problem i think is I have two ruby locations. i used the downloaded file from the source and rvm. /usr/local/bin/ruby & /usr/bin/ruby how do i uninstall one? is there any general command uninstall in linux? – raj May 11 '15 at 15:19
  • Judging by [this answer](http://stackoverflow.com/a/11536137/4861201) (which will also explain how to uninstall if that's what you want) those directories may be part of the same installation. Did you try sudo apt-get install libssl-dev ? Followed by recompiling – Evan Schwartz May 11 '15 at 15:37
  • If you go with the uninstall, you may just want to follow the video I linked on your next try – Evan Schwartz May 11 '15 at 15:39
  • [And here's some info on two ways to remove packages](http://unix.stackexchange.com/questions/118880/should-i-use-apt-get-remove-or-apt-get-purge) – Evan Schwartz May 11 '15 at 15:41
  • i tried sudo apt-get install libssl-dev then recompiled by rvm reinstall --disable-binary 2.1 .. it giving an error sayin "command gem pristine --extensions --version ' failed, you need to fix this gems manually." – raj May 11 '15 at 22:07