How can I restart Ruby after a gem install? - ruby

I'm running on Ubuntu. The question is so basic it feels silly but I have done some searching and can't figure out the answer.
Edit: I am running into similar issues as the following
Uninitialized constant using Twitter ruby gem

You don't need to restart Ruby after installing gems. You can for example
gem install rails
and after that you can start running rails (which uses Ruby) right away and no need to restart Ruby.

In Uninitialized constant using Twitter ruby gem link restart means ctr+c that is stop the server and rails s (for rails 3) that is start the server.

Related

Can't find installed gems

I am very new to ruby, and am using Ubuntu , I installed ruby last week and have been using it ever since. But when I decided to start studying rails I realised the rails server will not start, I decided to reinstall ruby, and then rails, which I did successfully.
But now when I install a ruby gem, I do not see it, not even when I type gem list on the terminal, it also throws an error when I try to run it in a program. I am very frustrated and do not know what to do..
Try installing RVM instead of ruby directly, this will install the required setting and it will be easier to beginners.
https://rvm.io/rvm/install

Rails server command generates error report

When I used rails server command, found following errors in terminal. It shows that "could not find a JavaScript runtime". I am newbie in ROR and don't know to configure different files. I Google and found solutions of this problem 1 2 3. Still I am not getting the things. Please suggest some solutions.
Ruby and Rail versions on my system
Ruby version:- ruby 1.8.7 , Rails version:- Rails 3.2.6
I suppose you lack executable on your system/
Haven't you try to run gem install execjs or bundle install(from your project directory) in console?
UPDATE
Also visit execjs homepage and try instaling any of JS runtimes supported.
UPDATE 2
I was able to reproduce your error (with ruby 1.9.2). Just add gem 'therubyracer' to your Gemfile and run bundle install. For some weird reason ROR is not working out of the box on Ubuntu. See this and search for runtime word for more info.
PS
Please put your Gemfile here. This might help.
The error message also tells your to
See https://github.com/sstephenson/execjs for a list of available runtimes.
You have to install one of the JavaScript runtimes listed there:
therubyracer
therubyrhino
Node.js
Microsoft Windows Script Host
For Rails 3.2.6 I suggest to use Ruby 1.9.3. for better performance.

Why does my Rails app not see installed gems?

Running Ubuntu 10, RVM, Passenger and apache2. Trying to configure and get Redmine running.
First, I set my default Ruby binary to /usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby. That's the output of which ruby. Output of which gem is /usr/local/rvm/rubies/ruby-1.9.2-p180/bin/gem. I think that side of things is set up properly.
I know Passenger is running, because I'm getting an error screen, with this error:
Error message:
Missing the i18n 0.4.2 gem. Please gem install -v=0.4.2 i18n
Update The error that passenger is producing is coming from the boot.rb file. I went and made a gist of the application's boot.rb file.
When I do check to see if that gem is installed, here's the output.
# gem list
# ... list truncated ...
# i18n (0.4.2)
(full gist of installed gems here)
Really? Let's first make sure passenger.conf is going to the right Ruby installation...
passenger.conf
PassengerRuby /usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby
>:| So now, I go onto SSH into the application directory, and what have you, script/server starts normally. I'm a little more than confused. Clearly the Ruby installation that Passenger is configured to has the Gem it says is missing, installed, and additionally, the application doesn't falter on a start up. Which makes me think it's a Passenger problem.
Using RVM with Passenger is a bit complicated, maybe this link about using Ruby and Passenger will help.

Sinatra doesn't load when running a ruby app

I'm trying to run a Ruby application that requires Sinatra within Ubuntu 10.10. I'm new to the 3 of these technologies so I understand if this question looks dumb to you.
Yesterday I installed ruby doing...
sudo apt-get install ruby1.9.1-full
And sinatra by doing...
sudo gem install sinatra
This is the code I'm trying to run:
require 'rubygems'
require 'sinatra'
get '/' do
"Hi Alex!"
end
When I do ruby1.9.1 -rubygems app.rb nothing happens (Ruby is properly installed since I tried running apps that don't require sinatra and they work OK).
$ ls
app.rb
$
$ ruby1.9.1 app.rb
$
$ ruby1.9.1 -rubygems app.rb
$
I know it should open Sinatra and tell me which port it is listening to.
I've been looking for help through the web and read several of the threads created within this forum but nothing I've tried has worked out for me.
What could be happening here?
Thanks
There was a similar problem with sinatra 1.0 on ruby 1.9.2. The answer there was to add enable :run to your code.
Have a look at the docs for the :run configuration - if you're going to be deploying to a server you'll want to do something like enable :run if __FILE__ == $0 so that you only start the built-in server during development when you need it.
Strictly speaking your code is correct and should run okay, and in fact it does with ruby 1.8.7 and 1.9.2. The problem seems to be running it with ruby 1.9.1. In general 1.9.1 seems to be fairly outdated and you should probably look to upgrade to 1.9.2 if you can. If Ubuntu doesn't have any packages for 1.9.2 take a look at rvm. (In fact if you're going to be doing ruby development rvm is worth a look anyway).
Update:
I managed to get ruby 1.9.1 compiled to test this, and your code worked ok. Also a bit of googling suggests that the Ubuntu ruby1.9.1 package provides ruby 1.9.2 anyway. So there seems to be something else going on causing :run not to be set when running the file directly, though I don't know what that could be.
Another update:
Looking at the Ubuntu Sinatra package it looks like it's at version 1.0. It could be that your setup is using the Ubuntu
package and ignoring the more recent version installed via rubygems. This could explain what's happening. If so this isn't a "a similar problem" to ruby 1.9 and sinatra 1.0 like I suggested above, it's the same problem!
Yet another update:
A couple of things have occurred to me. You can check what version of Sinatra you're actually using with something like puts Sinatra::VERSION after require 'sinatra'. Also, it looks like there is a gem1.9.1 command that corresponds to ruby1.9.1. It looks like when you installed sinatra with sudo gem install sinatra the latest version got installed into the ruby 1.8 install, and left ruby 1.9 with the Ubuntu packaged Sinatra 1.0. If you haven't switched over to rvm yet, you could try sudo gem1.9.1 install sinatra.

Ruby Twitter gem

-- UPDATE --
Ok its fixed. This is what I did. remove all ruby and rubygems completely. then install ruby1.9.1-full and rubygems1.9.1 then install the twitter gem.
Hi guys,
I am having trouble working with the Twitter gem. I am using ruby 1.8.7
After installing when I try to run a simple script I get this error
ruby twitter.rb
./twitter.rb:5: uninitialized constant Twitter (NameError)
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from twitter.rb:2
I running this on a Ubuntu box. I checked with gem -list and I see the Twitter (1.1.0) is listed there.
this is the code I am trying to run
require "rubygems"
require 'twitter'
puts Twitter.user_timeline("test").first.text
Any ideas ?
I believe it only works with Ruby 1.9 If you want to use twitter gem try version 0.9 with Ruby 1.8.x
This works for me:
ruby-1.9.2-p0 > require 'twitter'
=> true
ruby-1.9.2-p0 > puts Twitter.user_timeline("test").first.text
TExES Pedagogy and Professional Responsibilities EC-12 Teacher Certification Test Prep Study Guid… - by Sharon A Wynne http://amzn.to/f3kF74
=> nil
which version of ruby are you using?
gouravtiwari21's comment seems to fix the problem, but it's wrong to suggest that the twitter gem requires 0.9.0 if you want to run it using Ruby 1.8.x.
You can check out the version compatibility here:
http://travis-ci.org/#!/jnunemaker/twitter
It shows the twitter gem working with Ruby installs as low as 1.8.7.
For me, it was an issue with having the correct dependent gems, as well as the correct versions.
Here's how I got it working:
I ran:
sudo gem list
And compared the versions of specific gems with what I found here:
https://github.com/jnunemaker/twitter/blob/master/HISTORY.md (I simply searched for the word 'dependency' to see which versions twitter cared about.
I also found this diff:
https://github.com/jnunemaker/twitter/commit/ac8114c1f6ba2da20c2267d3133252c2ffc6b6a3
And I compared the gems listed there with what I had installed, and I just made sure my system lined up with what I was seeing in the version notes. Oftentimes what happened is that I had multiple versions of a gem, and for some reason, the lower version was taking precedence.
I'm not sure why I still have to add
gem 'twitter', '1.7.1'
to my Gemfile, but alas, that's the last step required in order to get this stuff working.
Don't forget to restart your server, and you should be good!

Resources