Rails Error Can't Find freedesktop.org.xml - ruby-on-rails

I've had some issues starting a new RAILS project, where I'm getting an error that there is a missing file /usr/local/share/mime/packages/freedesktop.org.xml. There was a connection with the mimemagic dependencies, and I found this issue on GitHub about the mimemagic version and licensing - https://github.com/rails/rails/issues/41750
Wondering if anybody else ran into the issue, and could explain what is going on.
I'm using rbenv with ruby version: 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19], and rails 6.1.3
Here is the error message in the command line:
Installing railties 6.1.3
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/nico/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/mimemagic-0.3.7/ext/mimemagic
/Users/nico/.rbenv/versions/3.0.0/bin/ruby -I/Users/nico/.rbenv/versions/3.0.0/lib/ruby/3.0.0 -rrubygems
/Users/nico/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.3/exe/rake
RUBYARCHDIR\=/Users/nico/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/extensions/x86_64-darwin-19/3.0.0/mimemagic-0.3.7
RUBYLIBDIR\=/Users/nico/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/extensions/x86_64-darwin-19/3.0.0/mimemagic-0.3.7
rake aborted!
Could not find MIME type database in the following locations: ["/usr/local/share/mime/packages/freedesktop.org.xml",
"/opt/homebrew/share/mime/packages/freedesktop.org.xml", "/usr/share/mime/packages/freedesktop.org.xml"]
Ensure you have either installed the shared-mime-types package for your distribution, or
obtain a version of freedesktop.org.xml and set FREEDESKTOP_MIME_TYPES_PATH to the location of that file.
Tasks: TOP => default
(See full trace by running task with --trace)
rake failed, exit code 1
Thanks,
Nico

Found some links to shared-mime-info on the GitHub link I posted, and I solved the issue by running the command below and starting a new project:
brew install shared-mime-info

If you are on ubuntu OS you can run below command
sudo apt-get install shared-mime-info

If migrating data from an Intel Mac (or an M1 Mac running Rosetta 2) to an M1, note that mimemagic will cache the old directory, so in addition to brew install shared-mime-info, you'll want to run:
gem uninstall mimemagic
gem install mimemagic

Related

gem install mimemagic -v '0.3.10' fails to install on Big Sur

Mac OS Big Sur 11.4
** Rails 6.1.0 **
however, my use case is for a Rails Engine that I am writing that targets Rails 6.1+ applications
xcode-select version 2384.
GCC version
% gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: arm64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
the gem I am trying to install is
mimemagic 0.3.15 installed with bundler
Bundler version 2.2.19
this is in a non-Rails application that uses bundler. in my app mimemagic is resolving (new) to 0.3.5, but won't install on Mac OS Big Sur
gem install mimemagic -v '0.3.10' --source 'https://rubygems.org/'
the result is
Building native extensions. This could take a while... ERROR: Error
installing mimemagic: ERROR: Failed to build gem native extension.
current directory: /Users/jason/.rvm/gems/ruby-2.6.3/gems/mimemagic-0.3.10/ext/mimemagic
/Users/jason/.rvm/rubies/ruby-2.6.3/bin/ruby -rrubygems
/Users/jason/.rvm/gems/ruby-2.6.3/gems/rake-13.0.3/exe/rake
RUBYARCHDIR\=/Users/jason/.rvm/gems/ruby-2.6.3/extensions/-darwin-20/2.6.0/mimemagic-0.3.10
RUBYLIBDIR\=/Users/jason/.rvm/gems/ruby-2.6.3/extensions/-darwin-20/2.6.0/mimemagic-0.3.10
rake aborted! Could not find MIME type database in the following
locations: ["/usr/local/share/mime/packages/freedesktop.org.xml",
"/opt/homebrew/share/mime/packages/freedesktop.org.xml",
"/opt/local/share/mime/packages/freedesktop.org.xml",
"/usr/share/mime/packages/freedesktop.org.xml"]
Ensure you have either installed the shared-mime-info package for your
distribution, or obtain a version of freedesktop.org.xml and set
FREEDESKTOP_MIME_TYPES_PATH to the location of that file.
This gem might be installed as a dependency of some bigger package,
such as rails, activestorage, axlsx or cucumber. While most of these
packages use the functionality of this gem, some gems have included
this gem by accident. Set USE_FREEDESKTOP_PLACEHOLDER=true if you are
certain that you do not need this gem, and wish to skip the inclusion
of freedesktop.org.xml.
The FREEDESKTOP_PLACEHOLDER option is meant as a transitional feature,
and will be deprecated in the next release.
/Users/jason/.rvm/gems/ruby-2.6.3/gems/mimemagic-0.3.10/ext/mimemagic/Rakefile:15:in
`locate_mime_database'
/Users/jason/.rvm/gems/ruby-2.6.3/gems/mimemagic-0.3.10/ext/mimemagic/Rakefile:39:in
`block in <top (required)>'
/Users/jason/.rvm/gems/ruby-2.6.3/gems/rake-13.0.3/exe/rake:27:in
`<main>' Tasks: TOP => default (See full trace by running task with
--trace)
rake failed, exit code 1
Gem files will remain installed in
/Users/jason/.rvm/gems/ruby-2.6.3/gems/mimemagic-0.3.10 for
inspection. Results logged to
/Users/jason/.rvm/gems/ruby-2.6.3/extensions/-darwin-20/2.6.0/mimemagic-0.3.10/gem_make.out
jason#Rose21 hot-glue % bundler -v Bundler version 2.2.19
--SOLVED--
TO FIX:
brew install shared-mime-info
or
sudo apt-get install shared-mime-info

Error installing ruby on rails on windows 10

I wanted to install ruby on rails for windows 10, following the same instructions of this video: https://www.youtube.com/watch?v=G-B_KUFNkQQ
When it finish the installation of ruby, I return to the console and after gem install rails, I get this error:
C:\Users\Usuario>gem install rails --no-document
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
current directory: C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mimemagic-0.3.9/ext/mimemagic
C:/Ruby27-x64/bin/ruby.exe -IC:/Ruby27-x64/lib/ruby/2.7.0/rubygems -rrubygems C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.1/exe/rake RUBYARCHDIR\=C:/Ruby27-x64/lib/ruby/gems/2.7.0/extensions/x64-mingw32/2.7.0/mimemagic-0.3.9 RUBYLIBDIR\=C:/Ruby27-x64/lib/ruby/gems/2.7.0/extensions/x64-mingw32/2.7.0/mimemagic-0.3.9
rake aborted!
Could not find MIME type database in the following locations: ["/usr/local/share/mime/packages/freedesktop.org.xml", "/opt/homebrew/share/mime/packages/freedesktop.org.xml", "/usr/share/mime/packages/freedesktop.org.xml"]
Ensure you have either installed the shared-mime-info package for your distribution, or
obtain a version of freedesktop.org.xml and set FREEDESKTOP_MIME_TYPES_PATH to the location
of that file.
Tasks: TOP => default
(See full trace by running task with --trace)
rake failed, exit code 1
Gem files will remain installed in C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mimemagic-0.3.9 for inspection.
Results logged to C:/Ruby27-x64/lib/ruby/gems/2.7.0/extensions/x64-mingw32/2.7.0/mimemagic-0.3.9/gem_make.out
I tried to solve making an update and "gem install mime-types-data" but stills with the same problem...
The Ruby Installer is Ruby+Devkit 2.7.2-1 (x64) and my ruby version is ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x64-mingw32]
Windows 10 ruby 2.6.2 install rails 6.0.0.rc1
Download the shared-mime-info from https://gitlab.freedesktop.org/xdg/shared-mime-info/uploads/0440063a2e6823a4b1a6fb2f2af8350f/shared-mime-info-2.0.tar.xz
Extract the downloaded package with 7Zip or WinRAR.
Place it in a location of your choice e.g. "C:\package".
Set a new Environment Variable with a name: FREEDESKTOP_MIME_TYPES_PATH and
browse value to the location e.g. C:\shared-mime-info 2.0\data\freedesktop.org.xml.in
Refresh terminal or CMD e.g. Command
refreshenv
And finally, gem install rails -v 6.0.0.rc1
windows 10
ruby : 2.5.8
I downloaded package from https://gitlab.freedesktop.org/xdg/shared-mime-info/ and then set the environment variable (Windows) FREEDESKTOP_MIME_TYPES_PATH to that path ("c:....\data\freedesktop.org.xml.in")
also I installed mime-types-data > gem install mime-types-data
at first it didn't work after closing and opening again the terminal it did.
tip: if you use vscode you need to reopen vscode
Mac
If you are using macOS, try the following
brew install shared-mime-info
bundle update mimemagic
the problem is that the mimemagic team yanked a lot of versions yesterday https://rubygems.org/gems/mimemagic/versions
now you have to install the package shared-mime-info in your distribution.
I would recommend using WSL for rails development in windows, it will save a lot of problems in the future.
after a quick google search, this seems appropriate:
from MimeMagic Github Page :
This process will also work on a Windows machine.
Download the package from
https://packages.debian.org/sid/amd64/shared-mime-info/download
Ensure the command line version of 7-Zip is installed
7z x -so shared-mime-info_2.0-1_amd64.deb data.tar | 7z e -sidata.tar "./usr/share/mime/packages/freedesktop.org.xml"
Place the file
freedesktop.org.xml in an appropriate location, and then set the
environment variable FREEDESKTOP_MIME_TYPES_PATH to that path.
Once that has been done the gem should install successfully.
Please note
that the gem will depend upon the file remaining in that location at
run time.
For MacOs or Linux - Install shared-mime-info package to resolve that issue.
macOS
$ brew install shared-mime-info
Debian, Ubuntu
apt-get update && apt-get install -y shared-mime-info

Bundle load error when invoking bundler

I'm trying to set up a ruby project and rather new to the process of automating via bundle. However when I try to execute any bundle command I'm met with the following error:
/usr/local/bin/bundle:26:in `load': cannot load such file -- /usr/lib/ruby/gems/2.3.0/gems/bundler-1.16.1/exe/bundle (LoadError)
from /usr/local/bin/bundle:26:in `<main>'
I have tried removing and reinstalling Ruby, as well as removing the bundler gem itself. But to no avail. My Rubygems version is 2.3.0 and the Ruby version is 2.3.1 which is the latest stable version for Ubuntu
Problem related to bundler==1.16.1 try to reinstall with bundler=1.16.0 for now.
gem uninstall bundler -x
gem install bundler -v 1.16.0 --force
More info and bug report can be found here: https://github.com/bundler/bundler/issues/6227
I was able to uninstall bundler -v '1.16.1' as described by Mr.Coffee, but in gem list it was still listed and marked as default.
I created a symlink then - very hacky, but the only thing which worked for me:
ln -sf /usr/lib/ruby/gems/2.3.0/gems/bundler-1.16.0 /usr/lib/ruby/gems/2.3.0/gems/bundler-1.16.1
The gem requesting bundler works now.

/usr/bin/ruby: bad interpreter: No such file or directory

I am using capistrano for deployment of rails application. But while i am deploying my rails code into server i am getting following error.
The deploy has failed with an error: Exception while executing on host 00.00.00.00: bundle exit status: 126
bundle stdout: /home/rod/.rvm/scripts/set: /usr/local/bin/bundle: /usr/bin/ruby: bad interpreter: No such file or directory
/home/rod/.rvm/scripts/set: line 19: /usr/local/bin/bundle: Success
How can i solve this issue?
It's an issue related to ruby upgrade but bundle package path was old. To resolve it you should reinstall the bundler package again using gem.
Uninstall from system
sudo gem uninstall bundler
Install again
sudo gem install bundler
After MacOSX High Sierra update got this issue. High Sierra updates ruby gem to version 2.3 but xcpreety command of Xcode 9 still using Ruby 2.0 which is unable to find now & gives bad interpreter.
Just go to Terminal & run
sudo gem install xcpretty
insert your password it will update your xcpretty to ruby v2.3 & that will resolve the issue.
Restart Xcode & do fresh clean build it works for me.
Hope it helps!!!

Rails 3 - Installation Problems...Could not find bcrypt-ruby-2.1.2

I'm working to install Rails 3 on a new MacBook Pro...
when trying to get my app going, I get the following error:
Could not find bcrypt-ruby-2.1.2 in any of the sources
Try running `bundle install`.
When I run bundle install, I get the following:
...
Installing bcrypt-ruby (2.1.2) with native extensions /Library/Ruby/Site/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
...
Any ideas what I'm doing wrong?
Also... When I run rails -v it returns:
Could not find bcrypt-ruby-2.1.2 in any of the sources
Try running `bundle install`.
There's a problem compiling the extension, most likely you are missing a C library or something like that. On my Mac it installed with no problem using ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0] installed with RVM.
Can you try gem install bcrypt-ruby to get more debugging output?
Are you using ports or brew or something else?

Resources