"unknown encoding name" when using gem command - ruby

On Windows 10 using the Cygwin environment, I get the following error:
$ gem list
ERROR: Loading command: list (ArgumentError)
unknown encoding name - CP20127
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass
I have
$ gem --version
3.0.
$ ruby --version
ruby 2.6.4p104 (2019-08-28 revision 67798) [x86_64-cygwin]
$ echo $LANG
en_GB
running in a mintty terminal (version 3.1.6)
I haven't used the gem command for months. It did work once, but of course any of the components involved, have been updated in between several times. I don't know where the encoding CP20127 comes from. It does not look like a valid encoding name or Windows code page name to me, but it indeed seems to be Windows is using:
$ chcp
Aktive Codepage: 20127
I never fiddled around with the code page and I wonder where this setting could come from, and why it could affect my gem command.
UPDATE
I tried the following:
chcp 850
After this, gem list works. Hence, the culprit was the codepage setting. Now my question: Since I never explicitly set the codepage anywhere, what could the most likely reason be for the incorrect codepage setting?
UPDATE 2
I found meanwhile that CP20127 is set by mintty, while in another terminal (say, the normal Windows command console, or the conemu console, my shell has CP850. I also found that CP65001 (Unicode Codepage) does not break the gem command.
JörgWMittag pointed out in his comment, that CP20127 is the ASCII codepage, so I wonder why the gem command does not work with it. In other words: Is it a bug in gem (because it should not bail out with this CP), or is it a bug in mintty (because it sets this CP), or do I miss something else?

Related

ruby and erb not responding in centos

I've installed ruby with rvm on a centos 6.3 VM and when I attempt to run ruby with no parameters (or erb for that matter) I get no response back, it just sits there.
Running 'ruby' just drops the cursor to the next line like it's waiting for more input or something else to happen. Typing any ruby commands during this time does nothing AFAIK. I do not get any errors, but I'm not exactly sure where to look. I have to control-c to break out of it.
Few interesting things:
(I'm fairly new to linux, so be gentle)
running the command ruby -v
gets me:
ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-linux]
so it seems like it's installed
running:
echo "puts 'hello'" |ruby
gets me:
hello
I've created a different user and then logged in with that user and the behavior is the same.
I've installed rails and then created a rails app and I can do rails c use the rails console
Other notes that may or may not be relevant:
I've recently installed KDE. I did have ruby working before installing KDE but I can't say it was the installation of KDE that messed it up.
I've already uninstalled ruby using rvm and reinstalled, same thing.
Uninstalled rvm and reinstalled.
I've no idea where to go with this or what information would be useful.
Run irb to get an interactive session. This is a REPL, a Read-Eval-Print Loop.
To see Ruby do something in response to running the interpreter and feeding it standard input interactively, try something like:
$ ruby
p :hello
^D
If you just type ruby, I'm not sure anything will happen until it reads the entire input file ... i.e., sees a Control/D indicating standard input end-of-file.
I believe your looking for irb - the interactive Ruby interpreter.
erb is an interpreter that expects a file argument.
$ erb hello-world.rb

Problem with Vim's Ruby plugin

I have just installed Vim and when ever I go to open in ruby file I get these errors:
Error detected while processing C:\Program files (x86)\Vim\vimfiles\ftplugin\ruby.vim
line: 76
Encoding::ConverterNotFoundError: code converter not found (UTF-16LE to ASCII-8bit)
line: 93
E121 :Undefined varaible: s:ruby_path
E15: Invalid expression: s:ruby_path
line: 76
NameError: uninitialized constant Gem::Quickloader
line: 93
I have Ruby 192 installed and I get this error even if I update ruby vim files.
These are the two lines those errors are referring to if it helps:
line 76: ruby VIM::command( 'let s:ruby_path = "%s"' % ($: + begin; require %q{rubygems}; Gem.all_load_paths.sort.uniq; rescue LoadError; []; end).join(%q{,}) )
line 93: let &l:path = s:ruby_path
Note that instead of editing ruby.vim file you can just add
let g:ruby_path = ':C:\ruby192\bin'
in your _vimrc file (or equivalent for your platform). That way you won't need to keep re-editing ruby.vim when you update it.
If you run RVM and want its default ruby, use:
let g:ruby_path = "/Users/allen/.rvm/rubies/default/bin"
If you set your ruby interpreter in your project .rvmrc file, you can create an environment variable in your .rvmrc:
rvm 1.9.2#projectname --create
export RUBY_BIN=`which ruby | sed 's/ruby$//'`
You can use environment variables in your .vimrc:
let g:ruby_path=$RUBY_BIN
(Note you should also set a default $RUBY_BIN in your .bashrc or .zshrc so this works outside of .rvmrc projects.)
If your ~/.rvm/rubies/default/bin path does not yet exist, you need to set your rvm system default of ruby. At your command prompt or terminal application, enter:
rvm use 1.9.2 --default
using whatever ruby version you need.
How did you install Ruby?
Go into irb and enter:
Gem.all_load_paths.uniq
which should return a list of paths to your install gems that Gem knows about also.
That's what is failing in your error message and leads me to suspect you are missing some path or environment info, because it looks like vim isn't able to find your Ruby gems correctly.
Encoding::ConverterNotFoundError is a core library exception, so that part is working, but it looks like the Gem command isn't working.
Your problem is probably Ruby 1.9 - AFAIK Vim only works with Ruby 1.8, so you might have to downgrade your Ruby version to get Vim working.
I opened the file "C:...\vim73\ftplugin\ruby.vim" and right before line 73 or so, where the code reads:
if !exists("s:ruby_path")
I added:
let s:ruby_path = 'C:\ruby192\bin'
So far vim seems happier about editing ruby files. Note I installed my ruby in the "C:" directory instead of "Program Files" to get a better pathname to ruby.exe.
My version of ruby.vim is dated 2010 Mar 15.
Updating to the latest release of Ruby 1.9.2 (1.9.2p180 (2011-02-18) at the time of posting) fixed this for me.
I was running 1.9.2p132 or so when I had the problem, which seems to have been patched around Dec 2010. You can check your current version by running ruby -v.

Error running autotest on Windows 7 with Rails 3, Ruby 1.9.2

Installing and running Rails 3 and Ruby 1.9.2 on Windows 7 went rather smooth. It's only now that I want to run autotest that I'm running into problems. The error looks frustratingly simple, but I can't figure out how to solve it.
I have the following gems in my Gemfile:
gem 'autotest'
gem 'autotest-rails-pure'
But then when I run bundle exec autotest, I get:
loading autotest/rails
style: Rails
C:\bin\Ruby192\bin\ruby -I.;lib;test -rubygems -e "['test/unit',
'test/unit/helpers/users_helper_test.rb', 'test/unit/user_test.rb'].each
{ |f| require f }" | C:/bin/Ruby192/lib/ruby/gems/1.9.1/gems/autotest-4.4.1/bin/unit_diff -u
'C:' is not recognized as an internal or external command,
operable program or batch file.
So something seems to go wrong in the formatting of some path, but I'm not sure where and how to solve it. I've tried running this under Cygwin, but to no avail.
I have also tried using the ZenTest gem instead of the autotest and autotest-rails-pure gems and that ran! However, it did not detect any if the test files in the default directories. So that seems to be of not much use either.
Who can help?
Oh, yes! I found the solution! The gems I need in this setup are:
gem 'ZenTest'
gem 'autotest-rails-pure'
The ZenTest gem generates the correct command line string (which actually just has the "unit_diff -u" behind the pipe, without the path). The autotest-rails-pure gem finds the correct test set.
I think this has to do with the way the Windows command shell interprets path names. Normally you can substitute "/" for "\" and it still works, but apparently not when you also use pipes. I'll bet if you can put quotes around the failing command (starting with C:/bin/Ruby192/...) Windows will recognize it as a string.

-bash is messed up?

Trying to figure out why I could not set up Heroku Gem and following this answer SO 2396004 (Heroku Gem Doesn't Work). I think I might have messed up my system.
Now I am typing heroku list and I get (-bash: heroku: command not found) and when I type in ruby -v I get (-bash: ruby: command not found)
BELOW IS THE MOST RECENT OUTPUT
zak$ export PATH=$PATHEXECUTABLE DIRECTORY: /Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
-bash: export: `DIRECTORY:': not a valid identifier
-bash: export: `/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin': not a valid identifier
ZKidds-MacBook-Pro:rails_projects zak$ export PATH=$PATH:/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
ZKidds-MacBook-Pro:rails_projects zak$ heroku list
-bash: heroku: command not found
ZKidds-MacBook-Pro:rails_projects zak$ cd ..
ZKidds-MacBook-Pro:~ zak$ export PATH=$PATH:/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
ZKidds-MacBook-Pro:~ zak$ heroku list
-bash: heroku: command not found
ZKidds-MacBook-Pro:~ zak$ echo $PATH
:/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin:/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
-bash: GEM: command not found
ZKidds-MacBook-Pro:~ zak$ gem env
-bash: gem: command not found
ZKidds-MacBook-Pro:~ zak$ heroko list
-bash: heroko: command not found
When you set PATH to just one value, you lost all the other places to search, such as /bin and /usr/bin. Set your PATH incrementally:
export PATH=/new/place/bin:$PATH
You can be more elaborate than that, but that basic technique works.
Meantime, logout and login again - that will get you going most easily. Alternatively:
export PATH=$PATH:/bin:/usr/bin
Additionally, your first line was:
export PATH=$PATHEXECUTABLE DIRECTORY: /Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
When you run export, it will export one or more variables, but the values must either be simple variable names, or must be variable assignments:
export SOMEVAR NOTHERVAR=new-value ...
The complaint -bash: export:DIRECTORY:': not a valid identifier` is telling you that 'DIRECTORY:' is not valid. It is not clear what you had in mind. And you got a similar complaint about /Users/zak/... not being an identifier.
You can set an environment variable for just one run of a command:
PATH=$EXECUTABLE_DIRECTORY:$PATH /Users/zak/bin/command
The environment of the command will include the value of PATH given; note, though, that the shell won't search for the command with that modified path.
...What I was trying to do was...
I'm not a user of either Ruby or Rails, but on my Mac (10.6.4), I can find:
Osiris-2 JL: ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
Osiris-2 JL: rails -v
Rails 2.3.5
Osiris-2 JL: which ruby rails
/usr/bin/ruby
/usr/bin/rails
Osiris-2 JL:
So, on my machine, both Ruby and Rails are in /usr/bin. I don't have Heroku installed AFAIK (not on my PATH, anyway). Your first export clobbered PATH; the second one added your Ruby 1.9.2 directory to the empty PATH. Apparently, Heroku is installed somewhere else, or is not yet installed at all. You changed directory - a built-in operation that does not require a working PATH; you added the Ruby 1.9.2 directory to your PATH again (which didn't change anything usefully). Heroku is still not found. You echoed PATH (another built-in) - I'm not clear where the GEM: command not found message comes from. And the commands gem and heroko (sic) were not found. So, your first command set in train the problems.
Then you commented:
In terms of what I was trying to do, I was just trying to set-up my heroku account and got stuck when I tried to add my public ssh key. The heroko gem I had installed (thought) was not registering. That is when I read through the stackoverflow question referenced above that suggested my path was incorrect. I closed terminal and reopened. Running stuff like ruby -v outputs, but running rails -v does not. Is there something still to do? Why would rails -v not output?
Specifically on rails -v I get "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:827:in report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:261:inactivate' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:68:in `gem' from /usr/bin/rails:18 "
This suggests that you have rails installed in /usr/bin (like I do), but the installation has been altered somehow so it is self-inconsistent. Either that or the messed up environment (PATH) is causing trouble. But usually, software can find its own bits'n'pieces, so it suggests there is something up. Part of the trouble may be that you're using a Ruby 1.9.2 program with some Ruby 1.8 software.
My personal policy is to leave o/s provided software strictly alone; I let the Mac updates take care of that. If I want my own version of something, I build it and install it under my control - I do this with Perl, sometimes with GCC, and with Git or SVN or Mercurial or other such software.
I would look at ensuring you have the Ruby 1.9.2 environment working fully, and worry about whether you need to update your Rails environment in parallel. I suspect that using Ruby 1.9.2 with Rails built for Ruby 1.8.x is causing some of the trouble - but I'm not certain of that.
The fact I think is you misunderstand the doc you are reading.
When you read "$PATHEXECUTABLE DIRECTORY" it's a placeholder to be substituate with the real path of what you want to add.
To do it properly, follow what Jonathan Leffler said.

I can't install Haml/Sass on Windows using RubyInstaller for Windows

I never used ruby before, I just wanted to play around with HAML and SASS. I downloaded and installed Ruby's Windows installer (v1.9.1). Then, I clicked ruby.exe (the icon with a black window and a multicolored gem in the picture). Finally, I typed gem install haml and pressed Enter. But nothing happened. Am I doing something wrong?
Reference picture:
alt text http://img707.imageshack.us/img707/9863/haml.png
You might need to put the path to Ruby into the PATH environment variable to do this, but this is how I do it:
I open up the command line utility. I then type ruby -S gem install <whatever>. This works like a charm.
I tried running Ruby and it shows a blank screen but lets me type code. When I press CTRL + C to cancel it then executes my code as well. Maybe you need to do that in the manner you are trying to right now. I just find it easier to just ruby -S <statement> instead. IronRuby gives me the REPL no problems though.
ruby.exe is the Ruby interpreter. If you want to type code into it, you obviously need to type Ruby code into it, not DOS command code.
The gem command is a DOS batch file (gem.bat). DOS batch files need to be run from the DOS command interpreter.
Installing Ruby using RubyInstaller, you get an shortcut in the Programs menu that let you open a command prompt with Ruby in the PATH
You use that in case you didn't select the option to add Ruby to the PATH.
Either case, the gem command you typed in should be entered at the command prompt, and not inside Ruby itself.
The latest build (rubyinstaller-1.9.2-p136.exe) had a problem. Rename the folder: c:\ruby192\lib\ruby\site_ruby or delete it altogether and this fixes "gem"
You can do "gem install compass" or if you're behind a proxy you might need to do.
gem install –http-proxy compass
Here's a blog post with all the details:
http://francisshanahan.com/index.php/2011/how-to-theme-sencha-touch-sass-windows/
Hope that helps,
-fs
this is how i installed ruby and sass on my windows machine: How to install ruby and sass on windows?

Resources