I'm quite new to Ruby (and Rails) and I've been trying to set up a Rails server that accesses a PostgresQL database on Windows. I apologize in advance if I'm missing something obvious. I am using the most recent Windows release of Ruby 2.3.0p0, and the most recent PostgresQL version, 9.6 Beta 2.
I've been following this guide somewhat loosely, as it is written for Ubuntu. I installed Ruby, the Rails gem and dependencies without a hitch. Basically, everything goes fine until I go to run the
rails server
command, and my command prompt complains that the specified module can't be found. I had the pg gem installed, so I tried a variety of fixes I found, such as putting libpq.dll in the ruby/bin folder, creating a 2.3 folder, and so on. Nothing worked until I removed the actual pg gem itself, whereupon my server magically booted up. I suspect that the pg gem was overriding the pg version installed by the
bundle install
command automatically run after the
gem install pg
but I'm not actually sure what was going on. Could someone clue me in on the details?
EDIT, some debugging info:
With the vanilla pg gem, rails s gives:
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/pg-0.18.4-x64-mingw32/lib/pg.rb:14:in `require': cannot load such file -- 2.3/pg_ext
After copying the 2.2 folder to a 2.3 folder, rails s gives:
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/pg-0.18.4-x64-mingw32/lib/pg.rb:14:in `require': 126: The specified module could not be found. - C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/pg-0.18.4-x64-mingw32/lib/2.3/pg_ext.so (LoadError)
gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.15'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: website_development
test:
<<: *default
database: website_test
production:
<<: *default
database: website_production
username: website
password: <%= ENV['WEBSITE_DATABASE_PASSWORD'] %>
I haven't actually linked the database to Rails yet; I wanted to make sure the Rails side was actually working first.
EDIT2:
I realized that MarsAtomic said PATH and not LOADPATH, and I realized that ruby wasn't in my PATH for some reason. However, it still doesn't work after adding ruby/bin to my PATH. I'm beginning to think that Windows is rejecting the .so file or something, because when I put a .rb file in the same location, it finds that without problem. I also ran file on the .dll and .so, and it reports that they are both PE32+, and my ruby is also 64-bit, so I don't think it's an architecture issue either.
It wasn't an architecture thing, but it was close. I believe the reason it couldn't load the module is because the pg_ext.so in question was compiled for Ruby 2.2 and I am using Ruby 2.3. Upgrading to pg 0.19-pre seemed to resolve the issue.
EDIT: I just found out how to build native extensions and I tried it out the pg 0.18.4 package. (extconf.rb -> devkit's make). I took the .so that was generated and placed it in the 2.3 folder. It didn't ask for the .def but I might need it once I actually link to my database.
If not working on gem 'pg' then try to gem 'postgresql' OR gem install postgresql just see working properly or no
Thanks
Related
I've seen other questions asked similar (like this one), however it's slightly different.
I created a brand new Rails API app with the command rails new backend -d=postgresql -T --api. I have the database all set up and connecting fine. Now I am trying to install the graphql gem. It's in my Gemfile, I've run bundle install, and the next step is to run the command bundle exec rails generate graphql:install according to the docs. When I run this however, I get this error:
/Users/jimmiejackson/.rvm/gems/ruby-2.5.5/gems/bundler-2.2.11/lib/bundler/rubygems_integration.rb:334:in `block (2 levels) in replace_gem': Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? sqlite3 is not part of the bundle. Add it to your Gemfile. (LoadError)
from /Users/jimmiejackson/.rvm/gems/ruby-2.5.5/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `<top (required)>'
from ...
from ...
I can't find any answers in the Github issues, Google or Stack. I'm not sure why I'd be getting a sqlite error when I installed with postgresql from new. It's been a little while since I last worked on a Rails app, what could be the issue?
Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.5'
gem 'rails', '~> 6.0.3', '>= 6.0.3.5'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 4.1'
gem 'bcrypt', '~> 3.1.7'
gem 'graphql', '1.9.17'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
gem 'rack-cors'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'listen', '~> 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'graphiql-rails', '1.7.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: movie_show_tracker_development
test:
<<: *default
database: movie_show_tracker_test
Well I finally got it worked out. I ended up having to start the project over from scratch again and used Ruby v.2.6.3/ Rails v.6.0.3.5 to get the graphql gem working appropriately. Not even sure those were the main culprits or not, but it appears to be working now!
I'm working on a rails4 app.
A colleague of mine recently changed the database we use to postgress. When I pulled his branch and try to run my server I get the following error:
could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
This is my database.yml
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: sciencevest_development
test:
<<: *default
database: sciencevest_test
production:
<<: *default
database: sciencevest_production
username: sciencevest
password: <%= ENV['SCIENCEVEST_DATABASE_PASSWORD'] %>
Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.2'
# Use sqlite3 as the database for Active Record
gem 'pg'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Bootstrap & sass
gem 'bootstrap-sass', '~> 3.3.5'
gem 'sass-rails', '>= 3.2'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# authentication
gem 'devise'
gem 'devise_invitable'
# authorization
gem 'pundit'
# roles
gem 'rolify'
# states
gem 'aasm'
# pretty development data
gem 'faker'
# uploading images & videos
gem 'carrierwave'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
source 'https://rails-assets.org' do
gem 'rails-assets-bootstrap'
end
group :development, :test do
# test suite
gem 'minitest-rails'
gem 'factory_girl_rails', '4.0'
# guards
gem 'guard'
gem 'guard-minitest'
gem 'database_cleaner'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
group :development do
gem 'guard-livereload'
end
When I run ps auwwx|grep postg I get this:
c5227806 42095 0.0 0.0 2432772 648 s001 S+ 5:47PM 0:00.00 grep postg
I also have this:
$ psql --version
psql (PostgreSQL) 9.4.4
And this(i dont know if they are different):
$ postgres -V
postgres (PostgreSQL) 9.4.4
Also this:
$ brew info postgres
postgresql: stable 9.4.4 (bottled)
Object-relational database system
https://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.4.4 (3014 files, 40M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/postgresql.rb
==> Dependencies
Required: openssl ✔, readline ✔
==> Options
--32-bit
Build 32-bit only
--with-dtrace
Build with DTrace support
--with-python
Build with python support
--without-perl
Build without Perl support
--without-tcl
Build without Tcl support
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
https://github.com/Homebrew/homebrew/issues/2510
To migrate existing data from a previous major version (pre-9.4) of PostgreSQL, see:
https://www.postgresql.org/docs/9.4/static/upgrading.html
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
postgres -D /usr/local/var/postgres
c5227806 at PALM00566449A in ~/desktop/dev_projects/rails_projects/sciencevest on carrierwave
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
/Users/c5227806/Library/LaunchAgents/homebrew.mxcl.postgresql.plist: No such file or directory
Any ideas? All the explanations I found online either didn't work or were too complicated to understand.
pg was not running as stated in the comments I had to run:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Then create and migrate database. Hopefully this helps someone!
After creating a Ruby on Rails skeleton (before pushing to master and Heroku) and running: bundle install, I sometimes encounter the following error:
An error occurred while installing pg (0.18.2), and Bundler cannot continue
Make sure that gem install pg -v '0.18.2' succeeds before bundling.
The following command remediates the issue altogether: bundle install --without production.
Why exactly does the aforementioned command remediate the issue? As I understand, the command bypasses production environment gems for deployment; so, is my understanding correct and why must this be the case? Thank you!
Here is my gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development do
gem 'sqlite3'
end
gem 'bootstrap-sass'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
The best resource answering the "why" component of this question appears to be explained thusly by Michael Hartl's Ruby on Rails Tutorial:
"Heroku uses the PostgreSQL database...which means that we need to add the pg gem in the production environment to allow Rails to talk to Postgres...Generally speaking, it's a good idea for the development and production environments to match each other as closely as possible, which includes using the same database, however we'll use SQLite locally and PostgreSQL in production."
So, basically it appears that the issue is a matter of maintaining conventions between two different environments- production and development (local)- and more specifically, database types (Postgres vs SQLite), which is why bundle install --without production is required:
"To prepare the system for deployment to production, we run bundle install with a special flag to prevent the local installation of any production gems (which in this case consist of ph and rails_12factor)...Because the only gems added are restricted to a production environment, right now this command doesn't actually install any additional local gems, but it's needed to update Gemfile.lock with the pg and rails_12factor gems."
If the remediation for Heroku deployment bundle install --without production is an acceptable alternative to bundle install, it just seems too bad to be true; if so, is there another setting or file I can revise in order to achieve the same results effected by the regular bundle install? Thanks!
So in my quest to get a ruby dev environment working, I've ran into an issue that seems...confusing to this ruby noob.
When executing rails server, it starts up as expected, but when you put in localhost:3000 to your standard web browser, it replies the following:
Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem 'sqlite3' to your Gemfile.
Now here's the confusing part. I have sqlite3 installed (the 64 bit version, as that is what I downloaded, and am running a 64 bit OS), as verified by gem query (here's the full list of gems)
Uninstalling and reisntalling didn't do a lick of good for the issue at hand, but it did install without a hitch. Also the gemfile for the project that I'm testing this with is the folliwing
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
As you can see, sqlite3 is specified in the Gemfile quite early on, yet for whatever reason when I try to load the main page, it acts like it's not there.
Particulars for this machine are the following that weren't mentioned earlier in the gems section:
Rails 4
Ruby 2
Windows 7
Anyone ever ran into this before?
I just had this issue too. Go into your Gemfile.lock file and search for the 'sqlite3' entry. You'll note it reads sqlite3 (1.3.8-x86-mingw32).
Change that to sqlite3 (1.3.8-x64-mingw32) and then run the bundle install command and everything should work like normal.
I faced same issue and this seems to be Windows 7 specific Env issue. My problem was resolved with below changes
Go into your Gemfile.lock file and update sqlite3 (1.3.8-x86-mingw32) to sqlite3 (1.3.8-x64-mingw32)
Run bundle install from the project directory. That will update Gemfile.lock. You also have to restart the Rails server.
Also see config/database.yml which specifies which gem to use for the database.
development:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
I'm trying to install ROR on my notebook (Debian Wheezy 64 bit).
On first I had this issue (enter link description here ) solved by the first answer.
Now the rails server starts, but surfing on the browser at localhost:3000 I get the following error:
Could not load 'active_record/connection_adapters/sqlite3_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.
I've installed ruby 2.0.0 compiling the source code, no errors or mistakes.
Then I've installed some needed libraries (sqlite3, libsqlite3-dev )...
Here is my GemFile:
'https://rubygems.org'
-# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
-# Use sqlite3 as the database for Active Record
gem 'sqlite3'
-# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
-# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
-# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
-# See https://github.com/sstephenson/execjs#readme for more supported runtimes
-# gem 'therubyracer', platforms: :ruby
-# Use jquery as the JavaScript library
gem 'jquery-rails'
-# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
-# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
-# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
-# Use ActiveModel has_secure_password
-# gem 'bcrypt-ruby', '~> 3.0.0'
-# Use unicorn as the app server
-# gem 'unicorn'
-# Use Capistrano for deployment
-# gem 'capistrano', group: :development
-# Use debugger
-# gem 'debugger', group: [:development, :test]
gem 'execjs'
gem 'therubyracer'
And in my database.yml:
-# SQLite version 3.x
-# gem install sqlite3
-#
-# Ensure the SQLite 3 gem is defined in your Gemfile
-# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
My gem version:
ruby 2.0.0
rails 4.0.0
sqlite 1.3.7
Came across this error playing around in Sinatra today when running rake db:create_migration. My error was erroneously specifying a "sqlite:" database type in app.rb when it should have been "sqlite 3 :". Example:
wrong:
set :database, 'sqlite:name.db'
correct:
set :database, 'sqlite3:name.db'
I've just struggled through this today. My error when trying to run rake db:create or rake db:migrate or running the server was slightly different:
/Users/lisa/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require': Could not load 'active_record/connection_adapters/sqlite_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile. (LoadError)
Note that it's trying to load sqlite_adapter, not sqlite3_adapter, despite the fact that my database.yml file is valid and does have 'sqlite3' in it. I did all kinds of things to my database.yml which caused me to realize that no matter what I tried (e.g. postgresql) rails was still trying to load sqlite. I finally looked around for something that was overriding database.yml and found it:
$ env | grep sqlite
DATABASE_URL=sqlite:////Users/lisa/dev/mango/devdb.sqlite
This was set for playing around with django and was screwing up my rails environment. Ouch.