Unable to integrate sqlite3 with ruby and rails - ruby-on-rails

Disclaimer: I checked the FAQs. I have tried Google, Reddit and YouTube and am posting here after exhausting all available options.
I'm using guides.rubyonrails.org to learn. However, SQLite3 has not downloaded on my system, despite following the instructions on the website.
So I typed 'gem install sqlite3' in the command line and it has thrown multiple errors related to mingw32, mingw64 and msys. The commonality of the errors being they are invalid or corrupted databases (PGP signatures).
The final error stated for installing sqlite3 was "failed to build gem native extension" followed by the directory and a suggestion to install it from the net.
I have installed it from sqlite.org and integrated it with the regular command prompt. Here it says "connected to a transient in memory database".
It is not integrated in the command prompt with ruby. Here it says "the term 'sqlite3' is not recognised as the name of a cmdlet, function, script file, or operable program."
I'm using a laptop using Windows 10 and have rails 6.0.3.2 and ruby 2.7.1 installed.
I tried progressing irrespective and my input was 'rails server' on the regular command prompt.
The following lines showed up -
Could not find gem 'sqlite3 (~> 1.4) x64-mingw32' in any of the gem sources listed in your Gemfile.
Run 'bundle install' to install missing gems.
Please advise how to progress or if there's anything I'm missing. Should I persist and try and fix the error in the ruby command prompt or move forward with the regular command prompt? None of them are working for me to progress my learning. Let me know if you require more information.
Thanks for your time and help.
EDIT: Here is the image for when I run gem install sqlite3.
2nd EDIT: Here is what I get when I run 'rails new blog' and 'bundle install' thereafter.
3rd EDIT: Here is the mkmf file where the problem exists as per command prompt.
4th EDIT: I followed the instructions on guides.rubyonrails.org/getting_started.html. I ran 'bundle install' only when it asked me to after I ran 'rails new blog' in the command line.
Similar error regarding mingw32, mingw64 and msys from the first image came up after I ran bundle install in blog. However, this time it stated Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

Related

Rails with Docker 'Could not find ... in any of the sources' for an existing gem

My rails application runs using a docker and everytime I try to execute any 'bin/rails' commands in the terminal of the docker container, it raises the following error
Could not find racc-1.6.0 in any of the sources
Run `bundle install` to install missing gems.
on executing 'gem list' I have checked that racc is installed as 'racc (1.6.0 default: 1.5.1)' and calling 'bundle install' as the app suggest raises the same error. I assumed that maybe the 'default: 1.5.1' is the problem but did not manage to come around this one so far. Also executing 'which racc' or 'bundle info racc' returns the correct version of racc which is 1.6.0.
Update:
an exception is 'bin/rails server' which means the application launches like usual but I cannot do migrations and console calls.
Trying to use other racc version did not do any better since using 1.5.2 raises the same error and 1.5.1 requires nokogiri-linux which I did not manage to install locally so far
please try “docker-compose run web bundle install” command. This should work
So, after trying a bunch of commands and re-deploying the image I figured out that in the end creating a new project would solve most of the issues. Unfortunately, I still did not find out the cause of this problem but I assume there might have been conflicts in the configuration or general problems in the project setting. So heres the solution summed up
Solution 1:
create a new rails project and make sure it has identical gem requirement as the original project (simple way of doing this is to copy/paste the content of gemfile from the original project)
run new project application and check if bin/rails console (optional)
copy the entire content of the new project into the original project (don't forget to back up original project before doing so)
Solution 2:
if your project directory has a hidden .bundle folder, delete it to prevent rails app from reading gems in vendor/cache. Check bundle info <gem-name> to see if gem path is set on the correct gem-directory
Probably not a solution for all cause but this was my last option to try when everything else failed

Invalid Ruby path '//bin/ruby' during Capistrano Bundle install

I have a long standing Rails app that runs on Ubuntu on another cloud service, but I'm migrating it to AWS.
The Capistrano 3 deployment gets so far, but it fails installing gems that require native building, with the following error (this is one example).
I've pasted the full error at the bottom, but the root cause error appears to be the path used to invoke ruby,
sh: 1: //bin/ruby: not found
The same gem[s] install fine when installed locally on the AWS server.
I've investigated, and confirmed that the deployment via ssh is using a non-interactive shell, but I'm setting the ruby path using all three of .bashrc, /etc/environment and using,
set :default_env, { "PATH" => "$PATH:/snap/bin" }
...but still no joy.
I suspect there's a problem with the way the path to invoke ruby is being formed, as //bin/ruby (with that double forward slash) is syntactically incorrect for bash shell.
It's as if there's an environment variable that should be set and inserted between those slashes is defined as an empty string (or just not defined), but I've checked env vars for non-interactive shell against the interactive shell, and all looks the same in interactive and non-interactive shells.
I'm not using rvm, as I don't need to, and would rather not add that complexity unless it's absolutely needed (and I don't think it should be).
Any ideas on why ruby is being invoked with that invalid path?
Full error details, for context and reference,
An error occurred while installing mysql2 (0.3.21), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.21' --source 'https://rubygems.org/'`
succeeds before bundling.
In Gemfile:
mysql2
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
/home/rails/myrailsapp/deployonaws/shared/bundle/ruby/2.3.0/gems/therubyracer-0.12.3/ext/v8
//bin/ruby -r ./siteconf20190520-13147-dgcr4x.rb extconf.rb
sh: 1: //bin/ruby: not found
extconf failed, exit code 127
OK, I figured out what was going on.
After 34 years of using Unix, I learned that '//' is valid syntax for a path, so that was a red herring.
The issue really was that ruby executable wasn't in //usr/bin
I experimented with linking from the actual path that ruby was located, but this just hit other issues with ruby versions (that old chestnut).
The eventual 'fix' was to start again with a fresh Ubuntu instance, and install ruby using
sudo apt install ruby-full
...rather than...
sudo snap install ruby --classic --channel=2.3/stable
...that I had used previously.
Using the apt install put ruby under /usr/bin, and all was right with the world again.
Thanks.

Attempting to re-install Ruby (version 2.0.0) on Rails (version 4.0.0) on Windows 7

I had Ruby-on-Rails installed, but it was Ruby version 1.9.3. It was installed via the Railsinstaller. Since I am just starting in RoR, I wanted to start with the most updated versions to go through the Ruby on Rails Tutorial. Rails was easy enough to update, but not Ruby itself.
I uninstalled the existing RailsInstaller, deleted the c:\Railsinstaller directory and downloaded the latest version of RailsInstaller, version 3.0.0-alpha.1.
Upon install it launches a command prompt window that should list the install infor for git, ruby and rails. Instead I got this error:
The system cannot find the path specified.
Rails Environment Configuration.
C:/RailsInstaller/scripts/config_check.rb:28:in ``': No such file or directory -
rails -v (Errno::ENOENT)
from C:/RailsInstaller/scripts/config_check.rb:28:in `run'
from C:/RailsInstaller/scripts/config_check.rb:83:in `<main>'
C:\Sites>
Line 28 is part of this block:
def run(command)
$stderr.puts "Running #{command}" if Config[:debug]
%x{#{command}}.chomp
end
and line 83 is this inside of a 'puts' block:
version: #{run "rails -v"}
manually running "rails -v"
C:\Sites>rails -v
'rails' is not recognized as an internal or external command,
operable program or batch file.
attempting "ruby rails.rb"
ruby: No such file or directory -- rails.rb (LoadError)
attempting to manually install the rails gem
c:\Sites>gem install rails --version 4.0.0
Fetching: i18n-0.6.4.gem (100%)
Successfully installed i18n-0.6.4
Fetching: atomic-1.1.10.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
The system cannot find the path specified.
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
C:/RailsInstaller/Ruby2.0.0/bin/ruby.exe extconf.rb
creating Makefile
Gem files will remain installed in C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0
.0/gems/atomic-1.1.10 for inspection.
Results logged to C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/atomic-1.
1.10/ext/gem_make.out
The gem_make.out only contains:
C:/RailsInstaller/Ruby2.0.0/bin/ruby.exe extconf.rb
creating Makefile
I attempted to install Railsinstaller 3.0.0 on a windows xp machine to test, and got the same error after the install, running "rails -v" failed in the same way, but running "gem install rails --version 4.0.0" worked.
Did something persist from the previous install that is preventing the new install from functioning properly?
I think something is still trying to go to the Ruby1.9.3 forlder and/or subfolders and failing, but can't find anything referencing that directory.
After a bunch of additional research and out side help, found this:
You’ve installed both RubyInstaller and DevKit following the instructions but during gem installation, you receive a message like this:
C:\devkit>gem install rdiscount --platform=ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing rdiscount:
ERROR: Failed to build gem native extension.
C:/ruby/bin/ruby.exe extconf.rb
C:/ruby/bin/ruby.exe: No such file or directory -- extconf.rb
(LoadError)
Or sometimes just this:
ERROR: Error installing rdiscount:
ERROR: Failed to build gem native extension.
C:/Ruby187/bin/ruby.exe extconf.rb
This has been reported to our group here and here.
After a long back and forth investigation, we found two possible causes for this issue: COMSPEC environment variable (scenario A) and AutoRun registry setting (scenario B), both described below:
Scenario A
Using a command prompt, invoke the following command:
SET COMSPEC
If in the output you see something different than cmd.exe as value for that variable, then please adjust it to use cmd.exe
Some tools might change your command processor command, which interferes with Ruby invoking child processes.
Change that and try to install the gem again.
Scenario B
If the problem persist, invoke the following commands in the same command prompt:
REG QUERY "HKCU\Software\Microsoft\Command Processor"
REG QUERY "HKLM\Software\Microsoft\Command Processor" /s
Execute each line individually. Once you run it, will see something like this:
HKEY_CURRENT_USER\Software\Microsoft\Command Processor
CompletionChar REG_DWORD 0x9
DefaultColor REG_DWORD 0x0
EnableExtensions REG_DWORD 0x1
PathCompletionChar REG_DWORD 0x9
The columns of information are Key, Type and Value. If you see a key named AutoRun, there is a chance this is the culprit of the error you’re receiving.
AutoRun interferes with Ruby messing with child process executing and by result, affecting gem installation. Please remove it with the following command:
REG DELETE "HKCU\Software\Microsoft\Command Processor" /v AutoRun
Once you’re done, try opening a new command prompt and executing gem installation again.
Scenario B ended up being the culprit and things began working properly once that was completed.
I apologize that this doesn't actually answer your question at hand, but I think it's still useful advice to you:
Consider downloading Virtualbox and installing some Linux (Fedora, Ubuntu) on it and doing your Rails development on that Linux virtual machine. It won't mess with your Windows system at all, but it will be much easier to develop Rails with.
Almost nobody develops Rails on Windows, everyone uses Mac or Linux it seems. And I always read people having problems setting it up on Windows. It just doesn't seem worth the effort to me when you have free tools out there to develop on Linux.
Again, sorry this isn't actually the proper answer to the question. Even once you find the answer to your problem, I'd still recommend you consider this advice. You're likely to have more problems with Rails on Windows.

How do I specify the path for Devkit?

I'm here on Windows 7 x64 and am trying to install Ruby on Rails from scratch. I just installed the RubyInstaller 1.9.3-p429 and now just ran the DevKit-tdm-32-4.5.2-20111229-1559-sfx. After doing ruby dk.rb install --force. I tried to test if it's setup correctly but run into:
c:\DevKit>gem install RedCloth --platform=ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
The system cannot find the path specified.
ERROR: Error installing RedCloth:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe extconf.rb
checking for main() in -lc... no
creating Makefile
Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/RedCloth-4.2.9 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/RedCloth-4.2.9/ext/redcloth_scan/gem_make.out
And this happens to all gems that need the Devkit. I guess I have to set the path specified but I have no idea what that means. How do I do that or what's the real problem here?
P.S.
A little bit of background. I did have RailsInstaller installed but I was getting the same error so I deleted everything. I also had NodeJs installed as well but deleted that too. I erased the PATH variables completely to start from scratch.
UPDATE
Trying the RailsInstaller gives me this error:
$ gem install json -v 1.8.0
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
The system cannot find the path specified.
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
c:/RailsInstaller/Ruby1.9.3/bin/ruby.exe extconf.rb
creating Makefile
Gem files will remain installed in c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/json-1.8.0 for inspection.
Results logged to c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/json-1.8.0/ext/json/ext/generator/gem_make.out
I hate to bump an old thread, but I wish to add to the answers just in case someone else comes by (likely as this is at the top of a Google search for a "Devkit PATH error").
After extracting the DevKit into a permanent directory and after you've navigated to the install folder within your shell and entered the "ruby dk.rb init" command, make sure you actually do the next step and install the devkit. After the init command, run "ruby dk.rb install" and that should fix many similar problems.
You need to include the Devkit/bin directory in your environment path. First, find out where Devkit was installed. For this example, we'll presume it's at C:\Devkit.
Next open your Advanced System Settings (accessible under MyComputer => Properties), and click the Environment Variables button. Under the 'user variables' section, edit the 'Path' entry to include C:\Devkit\bin. Note that this entry is semicolon delimited so you'll need to add a trailing (or prepending) semicolon to this string.
I was facing the excact same problem when I tried to install Cucumber until I tried using the --verbose parameter. For some reasons this worked out for me but I cannot really explain why. I am not considering it as a solution but it is worth a try.
The best that has worked for me always in these errors is: https://github.com/oneclick/rubyinstaller/wiki/Troubleshooting#wiki-gems_fails_comspec_autorun
If you installed the devkit as per standard guidelines on https://github.com/oneclick/rubyinstaller/wiki/Development-Kit#installation-instructions, then it's not the Devkit path but the incorrect Autorun regex key OR the incorrect command processor set by other tools that interferes with ruby gem installations. Give it a go.
I had this issue, Windows 8 x64, Ruby 2.2.3.
I tried everything from many posts and many answers but only this worked for me: Deleting old devkits and installing again.
I got it working after these steps:
Delete every folder you have ever installed devkit
Install (x64 - 64bits only) DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe from http://rubyinstaller.org/downloads/
Execute and install somewhere without spaces or anything on the path (I did c:\devkit)
Go to your system environments and add to the path c:\devkit and c:\devkit\bin
Open a CMD prompt as an admin, go to c:\devkit and type:
ruby dk.rb init
ruby dk.rb install --force
https://github.com/oneclick/rubyinstaller/wiki/Troubleshooting#error-failed-to-build-gem-native-extension
That details a couple scenarios that can cause this problem. Just in case the link dies, though. The first is where your COMSPEC system variable no longer has a full path to cmd.exe. The second is where some kind of autorun is in the registry--this is where you check:
REG QUERY "HKCU\Software\Microsoft\Command Processor" /s
REG QUERY "HKLM\Software\Microsoft\Command Processor" /s
REG QUERY "HKCU\Software\Wow6432Node\Microsoft\Command Processor" /s
REG QUERY "HKLM\Software\Wow6432Node\Microsoft\Command Processor" /s
And if you see any autoruns you delete them with something like:
REG DELETE "HKCU\Software\Microsoft\Command Processor" /v AutoRun

Rails Question: Sqlite3 dll not found on windows (even the old 1.2.3 version)

I followed the suggestion here: and the gem seemed to install correctly, but when I ran rake:db:migrate from the windows command line, I got a full on pop up saying:
"This application has failed to start because sqlite3.dll was not found. Re-installing the application may fix this problem"
which is really weird, because normally (when I have no sqlite3), I get a text error in line with the other debug statements on the command line.
I'm installing sqlite3-ruby -v 1.2.3 (but it does the same thing with ANY version of sqlite3 I try to install, now...even the newest one (1.2.5, which has a bunch of "No definition" errors when I try to install it))
Silly question but: you have installed the sqlite gem but have you installed the sqlite application yet?
The gem is just the way your rails program will talk to the real sqlite application. If you don't have that installed, then there's nothing for it to talk to. I'm guessing that installing sqlite application will install the sqlite3.dll and then it'll all work again.

Resources