pry command not found after installing gem - ruby

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).

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/

RVM trying to load old Ruby version

UPDATE: I just quit all instances of Terminal and opened a new window, and apparently the message is not showing anymore.
I uninstalled ruby-2.1.0, installed ruby-2.1.3 and made it the default with RVM on Mac OS X.
Now everytime I open a new terminal window I see this:
ruby-2.1.0 is not installed.
To install do: 'rvm install ruby-2.1.0'
I looked on .bashrc, .bash_profile, .profile and .rvmrc, but I don't see anything trying to use ruby-2.1.0. I also updated the .ruby-version files.
rvm list shows ruby-2.1.3 as the current and default ruby.
How do I stop that message from appearing?
When you go into a Rails project directory in your terminal, RVM looks up the .ruby-version file and if it finds it, it checks the Ruby version specified inside this file, then if that Ruby version is not installed on your system by RVM, it gives you the message you are getting.
This is actually very helpful, allowing to know your project is using a Ruby version which is not installed on your system
The solution for me was to just quit all instances of Terminal and reopen it.
If anyone else is having this problem, check also Ali's answer regarding the .ruby-version file.

How to install pry on Windows?

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.

RVM: Use Ruby everytime?

I have installed Ruby 2.1.2 using RVM on Ubuntu 14.04. It works the first time, but then I restarted the terminal and it didn't work anymore. I figured out that I had to type rvm use ruby-2.1.2 every time.
I have researched and found out that I had to set a default. I did that, but it stil doesn't work. I also checked that the .bash_profile and .profile files look right.
Can anyone help me with that?
I figured this out myself and now post this for future reference:
I had to check the setting 'use as login shell' in the gnome terminal. See "RVM can't set ruby as default" for reference.

No progress installing ruby via macports. How long should this action take?

I'm in the process of installing ruby using macports. I typed the following command into terminal:
sudo port install ruby
Terminal responded by returning some lines that indicated the action was working, then it just stopped returning any new lines. I typed:
which ruby
and didnt get a response, so I closed the terminal window and consequently ended the processes.
I opened a new terminal window and re-typed the original install command and now I get the following message:
Waiting for lock on /opt/local/var/macports/registry/.registry.lock
How should I proceed from here? Should I just wait? If so, how long? Will terminal try to complete this action twice? How can I know if it's working?
A more appropriate thing to check, when you've seen no progress, is your system's activity.
On Mac OS, you could either open "Activity Monitor" and sort by CPU, or open a terminal and type top -o cpu. Watch for some app showing consistent activity, especially something with "port" in the name.
To deal with the lock... odds are REALLY good it's stale since you cut it off at the knees by closing the terminal, so use sudo rm /opt/local/var/macports/registry/.registry.lock to remove it and retry if you want.
I will recommend RVM for installing new versions of Ruby. It's really convenient. Before you jump into RVM read the "Installation" and "Rubygems" pages entirely, and after installing RVM type rvm notes and follow the directions it spits out.
Finally, do not, under any circumstance, no matter how good an idea it seems to be, try to replace or upgrade the system version of Ruby installed by Apple. Apple installed it for their own use, and messing with it invites bad juju.
"Waiting for lock on /opt/local/var/macports/registry/.registry.lock" means MacPorts is already running and doing things. You could check for any running "port" processes in Activity Monitor. Wait until these tasks are finished (or terminate them if you don't care that they don't finish) before trying to do other things with MacPorts.
ps -A | grep tclsh if you can't find the running process so you can kill it.
A more recent way to install Ruby is via RVM. Not a direct answer to you question, but I would highly recommend it.
Here is another vote for rvm. If you are like me, and you program on a mac, but you deploy to some other *nix, then you can make sure you have the same version of Ruby (and Rails, and gems) on each, using rvm's gemsets.
Also, you can switch among gemsets easily, so that if you find a gem that you can't get working right with Ruby 1.9.2, then you can switch to 1.8.7 or some such whilst you try to figure it out. Stuff like that.
As far as I'm concerned, you can jump right in on your mac (as yourself, not using sudo) with rvm install 1.8.7 or rvm install 1.9.2. Then make sure you switch to use the correct rvm, and make the one you want your default, and you're golden. If it doesn't work, delete it - all the gemsets will be installed below your home directory in .rvm/*
The pain you are going through now will resurface when you try to keep your system version of Mac's ruby working with all the stuff you write -- RVM is definitely easier than using Mac's Ruby.
In addition to what the Tin Man mentioned, if other "lock" errors start coming up, I found disabling the internet connection for a moment was helpful to stop all port processes that were occurring.

Resources