Invalid Ruby path '//bin/ruby' during Capistrano Bundle install - ruby-on-rails

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.

Related

How do i fix the problem with gem command?

I have installed ruby (2.7.0) using
snap install ruby
before this, I removed ruby 2.3.0 by deleting all its files, after
sudo apt-get remove ruby
but now the gem command just doesn't work. I have reinstalled it, but whenever I use gem, I get this message,
bash: /usr/local/bin/gem: /usr/local/bin/ruby: bad interpreter: No such file or directory
Ruby is currently installed in
/snap/bin/ruby
Your system PATH is determining the wrong direction for gem.
PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting. (Wikipedia)
You can fix the problem by finding out which directory is being prioritized using which -a gem, then re-ordering your PATH.
I made a script to achieve this, here: reorderPathForExe.sh
To run this script, just use git clone and chmod +x, then pass the executable you want fixed as the argument to reorderPathForExe.sh (i.e., ./reorderPathForExe.sh gem for you):
git clone https://gist.github.com/f4f83b23386111bedd7f8199949601af.git
cd ./f4f83b23386111bedd7f8199949601af
chmod +x ./reorderPathForExe.sh
./reorderPathForExe.sh gem
you should probably be installing ruby with RVM or rbenv.

Gem installed but 'command not found'

I've installed a Ruby gem called wordmove to work with pushing and pulling my Wordpress sites but when I run wordmove commands I get the error command not found. I've done some research and I haven't come up with much, I've come to the conclusion based on what I've seen that my Ruby install is messed up.
I ran echo "$PATH" from my root and it returned the following:
/Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/brettgolding/.rbenv/shims:/usr/local/bin:/user/local/sbin:/usr/local/mysql/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin
I am a noob with the terminal so have no idea how to clean this mess up.
So you're working with rbenv. According to its README, you should run rbenv rehash after installing any gems that have an executable command. Also, run it anytime you install a new Ruby version.

RhoStudio build for iOS7 Simulator: "Gem rake not installed" error

I am trying to build a RhoStudio application for the iPhone-simulator on Mac OS X 10.9.1.
The build with XCode fails at
/bin/sh -c ~/.rvm/gems/ruby-1.9.3-p545/gems/rhodes-4.0.1/platform/iphone/build/rhorunner.build/Release-iphonesimulator/rhorunner.build/Script-5C0442920EFBE79D0014E5C6.sh
[31mERROR: Gem rake is not installed, run `gem install rake` first. (B [m
Command /bin/sh failed with exit code 127
Within the script (Script-5C0442920EFBE79D0014E5C6.sh), there is a "source ~/.profile" call which seems to mess up the environment for rake. The error can be reproduced by opening a shell and executing the source command. If i don't source, there is no error for rake.
Also, if i try to gem install rake after the source command, there is a confirmation that it has been installed but the error still occurs.
Anybody help?
This is one of those issues where there are way too many specific factors involved to easily come up with a solution; I'm going through the ropes myself with Rhodes in 10.9. The problem is because Rhodes constantly is changing environments (it's a real mess) so your environment, which tracks the paths to your Ruby installations and Gems, will be very volatile. Here are some tips that might help you diagnose the issue:
Try running gem which rake, which shows you the absolute path of your rake gem as visible to the calling script. You can place this in one of your config files like ~/.profile or ~/.bashrc to test different contexts.
You can also use gem env to see a full printout of the gem's configuration for your environment, and just plain env shows you the system (shell) environment. Look very closely for the variables GEM_PATH AND GEM_ROOT which show you where Rubygems and your gem libs are searched for, respectively.
Keep in mind using sudo before install will affect where your gems are installed; this depends on where you installed Ruby, which ruby manager (for RVM look in ~/.rvm) and whether or not you are using Bundler for instance.
Hope that helps. Also, if you are into Bash scripting I recently posted a tip for managing the environment paths that might help: https://coderwall.com/p/f_dlyg

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

Resources