How to install pry on Windows? - ruby

First off, I have read through previous questions and answers and have not found anything that solves my issue.
On the official Pry website, http://pryrepl.org/, it says that this will install pry for you: "gem install pry" however, I've tried doing that and get this error "ERROR: While executing gem ... (Zlib::DataError) invalid code lengths set"
Looking into more answers on how to install this, I've found suggesting to type in "gem install pry-windows", still no results.
Can someone take a step back to before typing that code and let me know what requirements are needed beforehand?
I have ruby installed and I generally use cmd to run my ruby files. I also have irb (Interactive Ruby) and have tried running the above commands there, also to no avail.
Where am I supposed to be running these commands "gem install pry", cmd or irb? Also, do I need to download any files beforehand?

After lots of digging around, I just figured it out.
I had to install RubyGems first. http://rubygems.org/pages/download When doing this for windows, follow the regular instructions, but then when you run "ruby setup.rb" make sure that you opened the command line using "Run as Administrator".
Hope this helps anyone else figuring out how to download Pry.

Related

Installed gems are not running

I am trying to install jekyll.
I run gem install bundler jekyll
After installing gems I run bundle init and get
bash: bundle: command not found
How can I fix it?
You can get a gem's directory using gem which. For example:
$ gem which jekyll
/home/username/.rvm/gems/ruby-2.6.4/gems/jekyll-4.0.0/lib/jekyll.rb
Then append the directory to your PATH:
$ export PATH="$PATH:/home/username/.rvm/gems/ruby-2.6.4:"
The reason why you are getting "command not found" after installing gems is because they were installed in a location that your bash shell does not yet know about. The way the computer looks up commands is by looking at the PATH, which is a list of folders where the computer should look for commands, such as bundle. The previous answer is on the right track, but unfortunately, the gem which command will only tell you about locations that are already in your PATH, which might not include the folder where bundler and jekyll were installed.
The location of the gems depends on how you installed Ruby, so without knowing that, I can't tell you what to put in your PATH. What I can tell you is that what you are experiencing is unfortunately very common, but there is a fix. To avoid needless frustration and to help people like you, I wrote a script that will automatically set up a proper Ruby environment for you, including updating your PATH and everything else that is necessary to be able to install gems and use them right away without getting any errors. Check out the links at the bottom of this answer to learn more about my script.
In the meantime, I can make some guesses and see if I can help. If you installed Ruby with Homebrew, then this should fix it:
Run this command:
echo 'export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/2.7.0/bin:$PATH"' >> ~/.bash_profile
And then quit and restart your terminal. Now you should be able to run bundle init.
If you are reading this and you are not the original poster, you might need to replace .bash_profile in the command above with .zshrc depending on which shell you are using. You can tell by looking at the error. If you are using zsh, it will say zsh: bundle: command not found.
You can read more about my script and other ways to fix the "command not found" error in these articles:
https://www.moncefbelyamani.com/troubleshooting-command-not-found-in-the-terminal/
https://www.moncefbelyamani.com/how-to-install-jekyll-on-a-mac-the-easy-way/
https://www.moncefbelyamani.com/the-definitive-guide-to-installing-ruby-gems-on-a-mac/

pry command not found after installing gem

After installing the gem pry, and typing pry in terminal, i get an error saying that the command is not found:
Successfully installed pry-0.12.2
Parsing documentation for pry-0.12.2
Done installing documentation for pry after 1 seconds
1 gem installed
-bash: pry: command not found
So much depends on the details of your ruby installation that its difficult to give you a recipe to follow that will work from this point, but the general answer to why you can't execute pry is that the pry binary is not in your PATH. If you find the place where your gem binaries live and add that to your PATH, then you will be able to execute pry. Exactly how to do that depends on how you've installed Ruby and how your environment is set up. For example, if you use rbenv, and want to use a binary immediately after installing it, then I know that you have to run rbenv rehash. But there may be other procedures to follow for other setups.
Maybe a simpler way for you to initiate a pry session is to execute irb instead, and from there you can require 'pry' and Pry.start
Be sure that you add pry to your Environment Variables (windows)
Write env in the start menu then pick Edit the System Environment Variables then go to tab Advanced then click on Environment Variables
In User Variables Select the Path then click Edit then New and past your ruby path for example C:\Ruby26-x64\bin (this directory if you go inside it you will see the pry there)
And Click ok then ok then ok.
Now close your terminal and open it again (the problem should be solved after that) [try to restart your PC if it didn't solve, then open the terminal and try again]
I came across the same issue. It got resolved simply after I restarted my terminal (I use iTerm2 on Mac).

zsh command not found: zeus, mailcatcher, etc?

I've been going over this for awhile now and can't seem to get it permanently resolved. Was hoping someone could clarify for me.
I'm pretty familiar with setting up my PATH and working with ZSH. I have a ton of custom helpers, plugins, etc. going on nicely.
But for some reason, when I do gem install gemname and attempt to use it globally, it occassionally says gem not found. I found this happening recently with zeus:
tmtm|master⚡ ⇒ gem which zeus
/Users/andrewmartin/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb
tmtm|master⚡ ⇒ zeus
zsh: correct 'zeus' to '_zeus' [nyae]? n
zsh: command not found: zeus
I had the same problem recently with mailcatcher and was never really able to get it installed or working. I had a couple really good Rails buddies take a look, they were confused as well.
Here's my PATH:
tmtm|master⚡ ⇒ echo $PATH
/Users/andrewmartin/.rbenv/bin:/usr/local/share/npm/bin:/usr/local/bin/npm:/Users/andrewmartin/.rbenv/shims:/Users/andrewmartin/.rbenv/:/Users/andrewmartin/.rbenv/bin:/usr/local/bin:/usr/bin:/Users/andrewmartin/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/local/opt/ruby/bin:/Users/andrewmartin/Dropbox/Favorites/dotfiles/bin
Any idea why some of these common, global gems are simply not found in the zsh shell? Happy to share any other information that would make this helpful. I am using rbenv.
I figured it out!
Simple!
Whenever you install a new gem with rbenv, you have to use the rbenv rehash command. It said it found one, so I just deleted the one that existed, then typed it again. When I opened a new terminal, both mailcatcher and zeus were magically available to me.
Awesome! Thanks to this post by the way.

RVM causing path issues with installed gems on Ruby 1.9.2 - unable to annotate, etc, do I need to reinstall RVM?

I'm on Mac OSX Snow Leopard. I tried to post a similar question to the RVM Google group but it did not seem to get posted.
I'm worried that I've done something fundamentally wrong with my RVM install that's causing these errors, that seems to be related to paths, at each step of the way. Have any of you seen this behavior before?
I started to teach myself Rails programming as of about two months ago with a working environment of Ruby 1.9.1 and Rails 3.0.3, based on a hivelogic install tutorial that had me modify my ~/.profile file and install the relevant bits to ~/usr/local/src/. For reference, the line in my ~/.profile file was this when I installed RVM, if that makes any difference:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/src:$PATH"
In my terminal I installed RVM as a user using the standard user github bash script.
I tried to install Ruby 1.9.2, which kept running into a weird error about a libfile somewhere. After much Googling I found someone on Stack Overflow that recommended renaming the ~/usr/local directory while performing the Ruby install -- I did this, and the install complete.
Then I did gem install rails and tried to do bundle install in my app, which gave an error when trying to install the SQLite3 gem (even though I already had SQLite3 installed and working). Again, I spent a day Googling this and eventually found "Unable to install sqlite3-ruby gem" that said if I used Macports to sudo port install sqlite3 it would work.
I tried that from the base directory, and Macports did its thing but it didn't fix the problem. Then I did the same thing from my app directory and it fixed the SQLite3 error I was getting.
Now I am able to run rails server and rails generate again, which is great, but then I tried to "annotate" my new model, and I get this error: http://pastie.org/1481570
I have not yet solved this issue, and have looked at many threads of similar issues. This, for example, did not solve my problem: https://github.com/james2m/annotate_models/commit/5997da9692c9b222e8d1be22dfad6ed8638c16a1
I even tried copying my source code directly into the rvm/user/ directory in case that relative path was causing problems, but it doesn't seem to have fixed anything. Maybe I need to uninstall RVM and re-install it as root instead of a user-level thing?
What do you think is the best way to get annotate to work and hopefully get RVM to play nice with my gems going forward?
I'm unfortunately REALLY new to terminal, code, etc, so any help would be much appreciated.
On Snow Leopard you should modify either ~/.bashrc or ~/.bash_profile, preferably the later. Also, RVM will not need anything in ~/usr/local since it's entirely self-contained in ~/.rvm.
RVM uses a nice little shell function to sense the needed directories and desired default Ruby. I suspect either the instructions you followed were very out of date, or poor recommendations. The current RVM installation requests you add:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
to your ~/.bash_profile
The RVM site has lots of troubleshooting tips for things like MySQL. I'd strongly recommend backing out of the things those other tutorials had you do, and refer to the instructions on RVM's site. It is very easy to get things working right if you do it the RVM-way.
Download and install Apple's latest version of XCode from their Developer site if you haven't already. There have been some broken versions shipped on the DVDs.
Install. In particular follow the "Post Installation" section.
Following that, do whatever rvm notes says to do as far as libraries. Following that, you should be able to use rvm info to gather useful info about your installation. It is your best friend.
Database integration will point you to how to fix MySQL's wagon.
RVM development happens fast. Keep it updated, at least once a week using rvm get head.
At that point you should be in a good place to start reinstalling gems.

Local installation of ruby / rubygems with no root access

I have a machine at work from wich I'd like to run a script that gathers some information about other machines. I want to do it in Ruby, since it's what I know best, but I've ran into some problems, all apparently due to the same reason: I don't have root access in this machine.
So what I did was: Download ruby source, configure (with --prefix pointing to somewhere under my home dir), make, make install. Alright, ruby runs fine. Then I did the same with rubygems and installed it. Ok as well, untill I went to install my first gem.
I downloaded the gem package (sigh, lots of firewalls, can't just "gem install" something remote), net-ssh, and tried to install it locally. Got the infamous "no such file to load -- zlib". Clues about this led nowhere, so I tried the next approach: getting net-ssh's source. When it tries to require 'openssl' (or when I try it from irb), I get "no such file to load -- openssl".
All of these problems, apparently, could be solved by apt-getting or rpm installing, or whatever. Only problem is: I can't!
Any suggestions as to how I might proceed?
Thanks for the help,
Marcelo.
Closing this now.
I had to ask someone with root access to install zlib-devel and openssl-devel (I'm on RHEL). Couldn't make it otherwise.
I'm guessing there's probably a way of using the stuff inside said packages without installing them as root, but I couldn't do it.
Did you try Ruby RVM?
You can download, compile and install a full-featured Ruby version on your home environment.
I recently did the same. The trick that worked for me is NOT to use a --prefix flag when you install rubygems.

Resources