I am completely new to Ruby, Rails, and MySQL. I am trying to start a new project and start the default server and I get the error listed below. I have the following installed:
Ruby : ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9.8.0]
Rails: rails (3.0.7)
MySql: mysql2 (0.2.7)
RubyGems: 1.7.2
Error is below:
$ rails s
/usr/local/lib/ruby/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle: dlsym(0x251680, Init_mysql2): symbol not found - /usr/local/lib/ruby/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle (LoadError)
from /usr/local/lib/ruby/gems/1.8/gems/mysql2-0.2.7/lib/mysql2.rb:8
from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `each'
from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `each'
from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.12/lib/bundler.rb:120:in `require'
from /Users/nelsonwittwer/Sites/simple_cms/config/application.rb:7
from /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:28:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:28
from /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:27:in `tap'
from /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:27
from script/rails:6:in `require'
from script/rails:6
I'm not quite sure where to go from here and would love any help you may have. Thank you.
make sure you have mysql2 gem installed in your ruby system. To check it use gem list -d. If mysql2 gem not found, in ubuntu you must install following library before install mysql2 gem :
# sudo apt-get install libmysqlclient15-dev (for mysql-5.*)
# sudo apt-get install libmysql-ruby ruby-dev
After that, you could install with sudo gem install mysql2 and make sure your adapter value inside database.yml is mysql2. Another issue is Library not loaded, you can view this link if that the problem Library not loaded: libmysqlclient.16.dylib error when trying to run 'rails server' on OS X 10.6 with mysql2 gem
You need the mySQL gem installed on your system.
Now, DO NOT use apt-get to install this, as apt-get often has old versions of the ruby libraries.
Also, I would highly recommend you use SQLite when starting out.
And, Bundler is also very helpful (described in the railstutorial)
On ubuntu/debian based distributions (and you really want to use MySQL):
If you are using ruby 1.8.x (check with ruby -v):
sudo apt-get install libmysqlclient-dev
sudo apt-get install ruby-dev
sudo gem install mysql2
If you are using ruby 1.9.x:
sudo apt-get install libmysqlclient-dev
sudo apt-get install ruby1.9.1-dev
sudo gem install mysql2
Related
First Of all Thanks in advance :)
When I try to install the gem in rails application so it shows error like below.
$ rake gems:install
Invalid gemspec in [/home/aspireedge/.rvm/gems/ruby-1.8.7-p374/specifications/carmen-1.0.0.beta2.gemspec]: Illformed requirement ["#<YAML::Syck::DefaultKey:0x7f630b62a000> 2.6.1"]
rake aborted!
undefined method `source_index' for Gem:Module
/home/aspireedge/.rvm/gems/ruby-1.8.7-p374/gems/rails-2.3.8/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path'
/home/aspireedge/.rvm/gems/ruby-1.8.7-p374/gems/rails-2.3.8/lib/initializer.rb:298:in `add_gem_load_paths'
/home/aspireedge/.rvm/gems/ruby-1.8.7-p374/gems/rails-2.3.8/lib/initializer.rb:132:in `process'
/home/aspireedge/.rvm/gems/ruby-1.8.7-p374/gems/rails-2.3.8/lib/initializer.rb:113:in `send'
/home/aspireedge/.rvm/gems/ruby-1.8.7-p374/gems/rails-2.3.8/lib/initializer.rb:113:in `run'
/home/aspireedge/Aspiree/pyromaniac/config/environment.rb:16
/home/aspireedge/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
/home/aspireedge/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:in `new_constants_in'
/home/aspireedge/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
/home/aspireedge/.rvm/gems/ruby-1.8.7-p374/gems/rails-2.3.8/lib/tasks/misc.rake:4
/home/aspireedge/.rvm/gems/ruby-1.8.7-p374/gems/rails-2.3.8/lib/tasks/gems.rake:17
Tasks: TOP => environment
(See full trace by running task with --trace)
when I try to update gem
$ gem update --system
Latest version currently installed. Aborting.
I aslo try to remove gem with rvm gemset empty
but still got error
Try upgrade your RubyGems and remove and install again the carmen gem:
gem update --system
gem uninstall carmen
gem install carmen
There is a PPA with up-to-date versions of Ruby 2.x for Ubuntu 14.04+:
$ sudo apt-get remove rubygems
$ sudo apt-add-repository ppa:brightbox/ruby-ng
$ sudo apt-get update
$ sudo apt-get install ruby2.4
$ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux-gnu]
I receive the following error message when running this command:
gem install rails -v 4.2.4
This is the error:
/Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/yaml.rb:5:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
/Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': dlopen(/Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/psych.bundle, 9): Library not loaded: /usr/local/opt/libyaml/lib/libyaml-0.2.dylib (LoadError)
Referenced from: /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/psych.bundle
Reason: image not found - /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/psych.bundle
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych.rb:7:in `<top (required)>'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/yaml.rb:6:in `<top (required)>'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems.rb:628:in `load_yaml'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/config_file.rb:326:in `load_file'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/config_file.rb:198:in `initialize'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/gem_runner.rb:75:in `new'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/gem_runner.rb:75:in `do_configuration'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/gem_runner.rb:40:in `run'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/bin/gem:21:in `<main>'
Please Help - this is causing me nightmares
It seems your ruby installation is missing psych (for YAML output).
Install libyaml with Homebrew: http://brew.sh; then try gem install rails -v 4.2.4
$ brew info libyaml
libyaml: stable 0.1.6 (bottled)
YAML Parser
http://pyyaml.org/wiki/LibYAML
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/libyaml.rb
==> Options
--universal
Build a universal binary
$ brew install libyaml
==> Downloading https://homebrew.bintray.com/bottles/libyaml-0.1.6_1.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libyaml-0.1.6_1.el_capitan.bottle.tar.gz
🍺 /usr/local/Cellar/libyaml/0.1.6_1: 8 files, 312.8K
REINSTALL RUBY
If the above solution doesn't work for you, reinstall Ruby from scratch with rvm or rbenv,
1) Try the instructions on this accepted answer: https://stackoverflow.com/a/38194139/1076207
—OR—
2) Remove all rvm files, then reinstall rvm: https://stackoverflow.com/a/38158619/1076207
—OR—
3) Remove all rvm files, then install rbenv: https://stackoverflow.com/a/38194231/1076207
After using one of the three options above, use http://bundler.io to install Rails:
$ mkdir ~/Documents/Repo
$ cd ~/Documents/Repo
$ gem install bundler
[…]
$ bundle init
Writing new Gemfile to /Users/username/Documents/Repo/Gemfile
$ echo "gem 'rails', '4.2.4'" >> Gemfile
$ bundle install
[…]
$ bundle exec rails new project_name
[…]
$ cd project_name
Personally, I recommend 3) switch to rbenv—I did.
The error itself clearly says that you should install libyaml first and then re-install your ruby. You can do it by running following commands.
sudo apt-get install libtool
rvm package install libyaml
rvm reinstall ruby-2.3.0
for more reference please see this answer
To install RoR on my Mac (v10.9.2), I decided to follow the instructions for Ruby 1.9.2 here: https://stackoverflow.com/a/8464619/2278546
"rvm install 1.9.2" was taking too long, so based on suggestions on SO, I used "rvm requirements" to install each of the requirements individually with macports. I then executed "rvm install 1.9.2" and it ran much faster.
When I tried to execute "gem install rail", I got an error message saying
activesupport requires Ruby version >= 1.9.3
As a result, I went back and tried again with 1.9.3:
rvm install 1.9.3
rvm --default 1.9.3
gem update
gem install rails
This time, during the rails install command, the process got stuck installing the documentation for rails. I decided to interrupt and run this instead:
gem install --no-ri --no-rdoc rails
This worked! I ran the following:
rails new pong; cd pong; rails generate controller welcome index
The last command in that string gave me the following error:
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/sid.rb:17:in
fiddle_func': uninitialized constant Spring::SID::DL (NameError)
from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/sid.rb:30:in
sid' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/sid.rb:39:in
pgid' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/server.rb:78:in
set_pgid' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/server.rb:34:in
boot' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/server.rb:14:in
boot' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/run.rb:36:in
block in boot_server' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/run.rb:34:in
fork' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/run.rb:34:in
boot_server' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/run.rb:18:in
call' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/command.rb:7:in
call' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/rails.rb:23:in
call' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/command.rb:7:in
call' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client.rb:26:in
run' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/bin/spring:48:in
<top (required)>' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/binstub.rb:11:in
load' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/binstub.rb:11:in
<top (required)>' from /Users/me/Coding/pong/bin/spring:16:in
require' from /Users/me/Coding/pong/bin/spring:16:in <top
(required)>' from bin/rails:3:inload' from bin/rails:3:in `'
Based on suggestions read here and here and elsewhere, I decided to try with a different compiler:
port install gcc46
CC=`which gcc-mp-4.6`
rvm reinstall 1.9.3
gem install
rvm reinstall 1.9.3
Same problem with this installation as well.
I suspect interrupting those builds might have left things in a bad state. First off, uninstall 1.9.2. 1.9.3-p545 is the oldest supported version, as of now at least.
Next, uninstall the gem 'spring-commands-rspec' and run a gem pristine -all. Then do another bundle install. FWIW, I am able to run spring on my 10.9.2 macbook. You may have to reinstall the xcode command line tools if your gcc is giving you issues.
Beyond all that, you don't need spring to run a rails app. It's primarily a helper during development and testing. Once you get things cleaned up, I would just remove the thing from your Gemfile until you actually need it.
I was able to get things running by mixing #Andrew's advice with some common sense...
I first cleaned up the mess I had made:
sudo rvm remove 1.9.2
sudo rvm remove 1.9.3
sudo rvm remove 1.9.3-p545
sudo gem uninstall spring-commands-rspec
sudo gem pristine -a
sudo port uninstall rvm
I then reinstalled rvm
sudo port install rvm
and reinstalled Ruby 1.9.3 with rails:
sudo rvm install 1.9.3
sudo gem update
sudo gem install --no-ri --no-rdoc rails
The problem as described above still occurred.
I then remembered that I had received the following message when installing Ruby (confirming Andrew's comment):
WARNING: Please be aware that you just installed a ruby that is no
longer maintained (2014-02-23), for a list of maintained rubies visit:
http://bugs.ruby-lang.org/projects/ruby/wiki/ReleaseEngineering
Please consider upgrading to ruby-2.1.1 which will have all of the
latest security patches.
So, I cleaned up again:
sudo rvm remove 1.9.3
sudo rvm remove 1.9.3-p545
sudo gem uninstall spring-commands-rspec
sudo gem pristine -a
Then, I tried installing Ruby 2.1.1 and Rails:
sudo rvm install 2.1.1
sudo gem update
sudo gem install --no-ri --no-rdoc rails
This time, I got no errors when I tried to run
rails new pong; cd pong; rails generate controller welcome index
This is not an ideal answer because I still couldn't get 1.9.3 to work, but it fits my purposes (I think). Anyone have any theories explaining why 1.9.3 doesn't work?
Thanks,
Grasswistle
I'm trying to deploy my Rails 4 app on Azure VM running Ubuntu 14.04.
Here's a logfile, atomic fails to install. ruby-v gives me ruby 2.0.0p451
Any ideas how to fix that?
azureuser#my-url:~$ sudo gem install atomic
Building native extensions. This could take a while...
ERROR: Error installing atomic:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:13:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/atomic-1.1.15 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/atomic-1.1.15/ext/gem_make.out
azureuser#my-url:~$ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-linux]
Your gems are using ruby1.9.1 and you are missing dev files.
So install that using this command
sudo apt-get install ruby1.9.1-dev
If you are not sure about your ruby version you can use this command
sudo apt-get install ruby-dev
Make sure you also have the build-essential package installed. You can check using dpkg -l | grep build-essential or simply run sudo apt-get install build-essential.
Personally I tried lots of things before realizing I was missing the above mentioned package.
[gkaykck#main myApplication]$ rails console
/usr/local/lib/ruby/1.9.1/irb/completion.rb:9:in `require': no such file to load -- readline (LoadError)
from /usr/local/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:3:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:3:in `<top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:20:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:20:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I have installed rails 3 on ruby 1.9.2p136, which is ok i guess. But i cannot start rails console and it gives me the error i copied. The apps worked great with ruby 1.8.7 and i never saw an error like this.
Any ideas what it could be?
Apparently ubuntu and ruby don't always catch dependencies like they should.
From the first google hit (yeah, I clicked on this stack-overflow in place #2 before checking out the first result.)
Navigate to the Ruby source and enter:
sudo apt-get install libreadline5-dev
cd ext/readline
ruby extconf.rb
make
sudo make install
So, if you're on another distro, make sure you install readline somehow (source/package), then run make/install on extconf from the source. I tried what gkaykck suggested of course but got this without readline already on my system.
$ ruby extconf.rb
checking for tgetnum() in -lncurses... no
checking for tgetnum() in -ltermcap... no
checking for tgetnum() in -lcurses... no
checking for readline/readline.h... no
checking for editline/readline.h... no
Recipe for those who use rvm:
rvm pkg install readline
rvm remove 1.9.3
rvm install 1.9.3 --with-readline-dir=$rvm_path/usr
In more details about it on https://rvm.io/packages/readline/
If you want another solution to this problem do this.
sudo apt-get install libreadline6
Then in your gem file add:
gem 'rb-readline'
Then
bundle install
And you should be all set.
I'd recommend using rvm (Ruby Version Manager) to manage your different versions of Ruby and switch between them. It does a pretty good job of compiling the various versions for you too. You can even create per-directory .rvmrc files to tell rvm what version of ruby to use in which directory (as well as use per-project gem sets if you want!)
First of all uninstall every ruby version you have.
After that display rvm requirements:
rvm requirements
You will get something like:
Requirements for Linux ( DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=11.10
DISTRIB_CODENAME=oneiric
DISTRIB_DESCRIPTION="Ubuntu 11.10" )
NOTE: 'ruby' represents Matz's Ruby Interpreter (MRI) (1.8.X, 1.9.X)
This is the *original* / standard Ruby Language Interpreter
'ree' represents Ruby Enterprise Edition
'rbx' represents Rubinius
bash >= 4.1 required curl is required git is required (>= 1.7 for
ruby-head) patch is required (for 1.8 rubies and some ruby-head's).
To install rbx and/or Ruby 1.9 head (MRI) (eg. 1.9.2-head), then you
must install and use rvm 1.8.7 first.
Additional Dependencies:
# For Ruby / Ruby HEAD (MRI, Rubinius, & REE), install the following:
ruby: /usr/bin/apt-get install build-essential openssl libreadline6
libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev
libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev
ncurses-dev automake libtool bison subversion
# For JRuby, install the following:
jruby: /usr/bin/apt-get install curl g++ openjdk-6-jre-headless
jruby-head: /usr/bin/apt-get install ant openjdk-6-jdk
# For IronRuby, install the following:
ironruby: /usr/bin/apt-get install curl mono-2.0-devel
Install all dependencies via apt-get.
After that install ruby 1.8.7. This version is required if you plan to use ruby 1.9.x
Now you can install ruby 1.9.3:
rvm pkg install readline
rvm remove 1.9.3
rvm install 1.9.3 --with-readline-dir=$rvm_path/usr
Note that you dont even need to install readline package via rvm if you had installed it using apt-get.
With CentOS 6:
Remember we are working from the ruby install dir, for me it was:
/opt/ruby-1.9.3-p194/ext/readline
If you see the following output, then readline is not installed:
$ ruby extconf.rb
checking for tgetnum() in -lncurses... no
checking for tgetnum() in -ltermcap... no
checking for tgetnum() in -lcurses... no
checking for readline/readline.h... no
checking for editline/readline.h... no
To install with RPM:
yum install readline-devel
Then build it:
ruby extconf.rb
make
sudo make install
Adding in the Gemfile
gem 'rb-readline'
and then bundle install
did the trick for me
Solution is to go to the source folder you compiled ruby => ext => readline than
ruby extconf.rb
make
sudo make install
If you're using RVM you can re-make readline. This fixed the issue for me. Instructions here:
no such file to load -- readline (Load Error)
use rvm remove to remove all ruby installed.
do a "which ruby" if you still get something, you need to reinstall rvm then install ruby using rvm.