jekyll installed but 'command not found' - terminal

I installed jekyll, but surprisingly somehow osx doesn't recognise its installed.
$ sudo gem install jekyll
Password:
Successfully installed jekyll-1.2.1
Parsing documentation for jekyll-1.2.1
Done installing documentation for jekyll after 1 seconds
1 gem installed
$ jekyll
-bash: jekyll: command not found
gem environment ( - INSTALLATION DIRECTORY: /usr/local/Cellar/ruby/2.0.0-p247/lib/ruby/gems/2.0.0 )
$ cd /usr/local/Cellar/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/
echo $PATH
/usr/local/bin:/usr/local/sbin:~/bin:/usr/local/bin:/usr/local/sbin:~/bin:/Users/TheSpiritMolecule/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/TheSpiritMolecule/.rvm/bin

I have rbenv installed and the step I missed was to do an rbenv rehash after gem install jekyll. The rehash creates a link in ~/.rbenv/shims which is in included in $PATH.

Okay I had to check what exatly does the $PATH means, and for what it is.
The problem was simple, somehow my ruby installion directory wasnt in my $path variable.
Useful links: Mac OS X: Set / Change $PATH Variable
Okay so here is the thing how I solved it:
echo "$PATH"
gem uninstall jekyll
find / -name jekyll (to delete if there is any leftovers somewhere )
gem environment ( get EXECUTABLE DIRECTORY path )
nano $HOME/.bash_profile ( go to the end of document and insert a new line )
export PATH="/usr/local/Cellar/ruby/2.0.0-p247/bin:$PATH"
you can do this on a templorary way by just writing it in terminal and not saving it in your .bash_profile

Following steps solved my problem
gem uninstall jekyll
sudo gem install jekyll
Open ~/.bash_profile and add this code in the last line,
export PATH=$PATH:/usr/local/lib/ruby/gems/1.9.1/gems/jekyll-2.5.2/bin
Save and close the .bash_profile
Close and reopen the mac terminal, try running jekyll now, it should work

Related

Gem:File Permission Error Issue with gems (not duplicate)

I have been trying to install jekyll and bundler, and I keep getting this error:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
I have tried so many things suggested by other posts. Ran rbenv, appended eval "$(rbenv init -)" to my bash_profile in order to run it automatically, did some stuff with sudo, and also tried installing using:
gem install jekyll --user-install
but then when I try to make a jekyll command the return is:
-bash: jekyll: no command found
I am at a loss. I know basically nothing about Unix and have been trying this for hours. Any thoughts?
P.S. Please do not mark as duplicate because other posts have not answered my question.
It seems you haven't add the user gem bin dir to the PATH.
ruby -rubygems -e 'puts Gem.user_dir'
this will show the gem user dir.
then add OUTPUT_FROM_LAST_CMD/bin to your path, or simply add
export PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin":$PATH
to your ~/.bashrc
http://guides.rubygems.org/faqs/#user-install

Not able to install a gem file?

Hi People I am trying to install a gem file through command prompt on MAC using the following command "gem install filename" but whenever I try to execute the command I get the following error
WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
/usr/bin aren't both writable.
WARNING: You don't have /Users/hemmanshu/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
ERROR: Error installing frank-cucumber-0.8.14:
cucumber requires gherkin (~> 2.10.0, runtime)
every time I try to execute this command the same thing pops up.
You need to install gems with superuser privileges so you should to use
sudo gem install [gemname]
instead of
gem install [gemname]
U try with sudo. like "sudo gem install filename"
...Most of the time this is a PATH issue, Suppose you are using zshell as me, then add this line at the end of ~/.zshrc file
export PATH="$PATH:$HOME/.gem/ruby/2.1.0/bin"
If you are using bash as default shell then add this line to end of ~/.bashrc file
export PATH="$PATH:$HOME/.gem/ruby/2.1.0/bin"
For your case it will be like this:
export PATH="$PATH:$HOME/.gem/ruby/1.8/bin
Lastly don't forget to reload the shell by source ~/.zshrc incase of z-shell or source ~/.bashrc incase of bash-shell. I think this helps someone.

How do I run a Ruby Gem?

This might seem stupid, but I recently tried to install SASS and followed their instructions:
$ gem install sass
$ sass --watch [...]
So I followed along:
root#server:~# gem install sass
Successfully installed sass-3.1.15
1 gem installed
Installing ri documentation for sass-3.1.15...
Installing RDoc documentation for sass-3.1.15...
root#server:~# sass
bash: sass: command not found
Despite looking around like an idiot trying to find some simple way to run something like gem run sass or some other workaround to make it function, I am more or less at a loss.
It seems that Debian/Ubuntu drops ruby gems into /var/lib/gems/1.8/bin.
So the solution (at least for Ubuntu/Debian) is:
$ sudo -s
# echo 'PATH=/var/lib/gems/1.8/bin:$PATH' > /etc/profile.d/gemspath.sh
# chmod 0755 /etc/profile.d/gemspath.sh
...and then open a new shell session.
(This is fixed in Ubuntu 11.10.)
If you happen to have installed Ruby through rbenv, you'll need to execute the following command
rbenv rehash
On macOS I had to add the gem executable directory to the path.
Add these lines to your ~/.bashrc file, and reopen the terminal to refresh the env vars.
# gem
gembin=`(gem env | sed -n "s/.*EXECUTABLE DIRECTORY: \(.*\)/\1/p")`
export PATH=$gembin:$PATH
If you use macOS and you:
I don't know/care about Ruby.
I just want to run this program.
Why is this so complicated?
Then run:
~/.gem/ruby/*/bin/jekyll
where jekyll is the thing you just installed with gem install.
If you're trying to run a simple WEBrick server for your gem you can do the following after installation:
sass start

Trouble on uninstalling RVM

I am running Ubuntu 10.04 Lucid and I was probably wrong to uninstall RVM and now it seams to be not completely removed from the system. Now I would like to install that again but I am in trouble.
What happens is that I have strange outputs generated when I try to execute some command lines:
# Note that following command lines don't output the version
# (between the word "version" and the word "is") as it should be.
$ rvm
$ rvm -v
> -bash: /usr/local/rvm/scripts/base: No such file or directory
> A RVM version is installed yet 1.10.3 is loaded.
> Please do one of the following:
> * 'rvm reload'
> * open a new shell
# Even if I use the 'cd' command I have problems...
$ cd ..
> -bash: /usr/local/rvm/scripts/initialize: No such file or directory
> -bash: /usr/local/rvm/scripts/hook: No such file or directory
That probably means that RVM is not correctly removed even if Ruby seams to be running as well:
$ which ruby
/usr/local/bin/ruby
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
So, what I can do to completely remove/uninstall RVM?
UPDATE
I solved part of the problem (or, maybe, all problems): that (those) was related to Phusion Passenger that was still loading the old path related to the Ruby version managed by RVM.
first try echo $rvm_path - if that shows anything - rm -rf it
second:
sudo rm -rf /ust/local/rvm /etc/rvmrc /etc/profile.d/rvm.sh ~/.rvm*
next check ls -l /usr/local/bin | grep rvm this will show links to rvm - rm -rf them
and last which rvm - if it shows anything try to check this path and remove at least this file.
RVM installs everything into ~/.rvm. To remove RVM from your system run 'rm -rf ~/.rvm'.
Refer this. and where is everything installed to?
From rvm help:
implode - (seppuku) removes the rvm installation completely.
This means everything in $rvm_path (~/.rvm || /usr/local/rvm).
This does not touch your profiles. However, this means that you
must manually clean up your profiles and remove the lines which source RVM.
Judging from your $PATH you can also (alternatively) remove all of the following files and directories:
/usr/local/rvm
/etc/rvmrc
/etc/profile.d/rvm.sh

Jekyll - command not found

I am trying to get Jekyll running but I have no experience with Ruby.
As far as I can tell the installation of Jekyll has succeeded.
However:
$ jekyll
Gives an error:
-bash: jekyll: command not found
This is the gem env result:
- RUBYGEMS VERSION: 1.3.4
- RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin10.0]
- INSTALLATION DIRECTORY: /Volumes/HDD/DADU/gems
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /Volumes/HDD/DADU/gems/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-10
- GEM PATHS:
- /Volumes/HDD/DADU/gems
- /Volumes/HDD/DADU/.gem/ruby/1.8
- /Library/Ruby/Gems/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://gems.rubyforge.org/
And I found the following paths leading to "something" Jekyll:
~.gem/ruby/1.8/gems/jekyll-0.11.0/lib/jekyll.rb
~.gem/ruby/1.8/gems/bin/jekyll (exec file)
If you are using MacOS, from the Troubleshooting guide:
Jekyll & Mac OS X 10.11Permalink
With the introduction of System Integrity Protection, several directories that were previously writable are now considered system locations and are no longer available. Given these changes, there are a couple of simple ways to get up and running. One option is to change the location where the gem will be installed (again, using sudo only if necessary):
$ gem install -n /usr/local/bin jekyll
For others coming here with the following set up:
OS X + brewed install of ruby + (possibly) zsh
I figured the problem is that after installing jekyll as per their instructions, gem installs the jekyll gem in the brew cellar, not where the OS usually expects it (somehwere in a gem directory for ruby).
So, all that was needed here was to find out where the brew install of ruby installs gems, locate the jekyll binary, and create a symbolic link to it in /usr/bin.
Here is are the steps I took to fix it:
Type gem env and look for GEM PATHS. For me it was:
/usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1.
Make sure you can see the jekyll binary in the directory from 1 above and copy its path (if you can't, search any other paths listed in GEM PATHS for it). For me it was:
/usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/jekyll-1.4.3/bin/jekyll
Use the path from step 2 above to create a symlink to /usr/bin/jekyll. I did it by typing this (you might need sudo to create the symlink):
cd /usr/bin && ln -s /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/jekyll-1.4.3/bin/jekyll jekyll
Now all should be merry if you type jekyll.
The easiest method of doing this is to use RVM. It manages Ruby and all its gems for you and it's easy to use. See this link for using it.
If you did not want to use that you will need to modify your PATH variables so it can find your gems. I have found this to be tedious and reverted to RVM, but here are the general steps.
You will need to find out where your gems are getting installed. If you did gem install ... the gems will be in ~/.gem/ruby/1.8/gems/bin, if you used sudo gem install ... the gems will be somewhere in /System/Library/Frameworks/Ruby.framework/Versions/1.8/Resources
You have to add this path to your PATH variable. Easiest way to do this is by running :
echo 'PATH=$PATH:above/path/to/gems' >> ~/.bash_profile
If you are using RBENV instead of RVM you simply need to run rehash in the command line after installing jekyll:
rbenv rehash
I installed my ruby2.6.0 and gem via brew on MacOS 10.14.
For me, add the following line to my ~/.zshrc solved this issue.
export PATH=/usr/local/lib/ruby/gems/2.6.0/bin:$PATH
I found jekyll executable file with command locate jekyll.
Maybe a little late, but...
I had some trouble to install Jekyll on Ubuntu and tried everything that people answered in this thread - unfortunately nothing worked.
Then, I watched a video on Jekyll's site and after installing the whole ruby package again, sudo gem install jekyll worked.
Try it before anything else:
sudo apt-get update
sudo apt-get install ruby-full
sudo gem install jekyll
jekyll -v
It seems pretty simple, but it works on Ubuntu.
One solution would be editing your ~/.bashrc file and add this line:
PATH=$PATH:~/.gem/ruby/1.8/gems/bin
This will add ~/.gem/ruby/1.8/gems/bin in Bash's lookup path.
Reopen the terminal and it should work. Or you can use the following command:
. ~/.bashrc
Following steps solved my problem
gem uninstall jekyll
sudo gem install jekyll
Open ~/.bash_profile and add this code in the last line,
export PATH=$PATH:/usr/local/lib/ruby/gems/1.9.1/gems/jekyll-2.5.2/bin
Save and close the .bash_profile
Close and reopen the mac terminal, try running jekyll now, it should work
For me, I followed this installation guide instead of their main page's installation instruction. It worked after I changed the bash_profile file and restarted Terminal.
Jekyll is a ruby gem : Ruby gems in linux, for example, are in /var/lib/gems/1.8, as can be seen in the "ruby env" output.
Thus, you need to add the executables in this directory to your path.
In general, if a ruby gem is "not found" by your OS, it simply indicates that either
1) You don't have the gem installed or
2) You don't have the gem installed in a directory that is on your path.
I have found that there have been a few issues with installing ruby and ruby gems on linux (I have found that it can be tricky on Ubuntu v10, and have confirmed this with the Ruby folks on IRC). Thus, tools like RVM or rbenv might be the best approach to setting up a stable, maintainable ruby environment.
Easier than creating a symlink just install it correctly.
If you got permission errors like a lot of people are getting when trying to use
gem install jekyll
instead use
sudo gem install jekyll
#jayunit100,
I'm running into the same issue with a Jekyll blog. I've installed the gem via RVM in a 'Blog directory and the _config.yml file says that it should generate into Blog/_site. Is it as simple as adding Blog to the PATH or is there something else I'm missing?
Update: My bad, I didn't really have the gem installed. Lesson learned: rvm requirements and brew doctor are there for a reason - before you install stuff USE THEM
In my case I had to run bundle install --force
Then bundle exec jekyll serve works, but jekyll serve still doesn't. It seems I'll have to go with the former from now on…
When you use the --user-install option, RubyGems will install the gems to a directory inside your home directory, something like ~/.gem/ruby/1.9.1. The commands provided by the gems you installed will end up in ~/.gem/ruby/1.9.1/bin. For the programs installed there to be available for you, you need to add ~/.gem/ruby/1.9.1/bin to your PATH environment variable.
For example, if you use bash you can add that directory to your PATH by adding code like this to your ~/.bashrc file:
if which ruby >/dev/null && which gem >/dev/null; then
PATH="$(ruby -r rubygems -e 'puts Gem.user_dir')/bin:$PATH"
fi
https://guides.rubygems.org/faqs/#user-install
I put it in the .bash_profile (Mac OS X).
https://hathaway.cc/2008/06/how-to-edit-your-path-environment-variables-on-mac/
Here's an updated answer for 2020 (soon 2021). To install any Ruby gem, whether it's Jekyll, Bundler, Rails, etc., you need a proper Ruby development environment on a Mac. There are various ways to install Ruby on a Mac, as I have written about in great detail in my definitive guide to installing Ruby gems on a Mac. The only one I recommend is to use a Ruby manager because it's the most flexible and sets you up for success for the long term. My preferred one is chruby because it's the lightest and easiest to use. As part of installing Ruby, you also need to properly configure your shell startup file (typically ~/.zshrc or ~/.bash_profile) so that it knows where to find the gems you install. Otherwise, you'll get the "command not found" error, which I've also written about.
Since there are several steps involved in setting up a working Ruby development environment on a Mac, I wrote some scripts to automate the whole process and make things easier and faster for people. You can read more about the scripts in my guide mentioned above.
I had this problem for a very stupid reason, which is that I was working on Linux and had installed both flatpak and .deb versions of Visual Studio Code. I was confused because I could successfully run bundle exec jekyll serve in the terminal application, but not from the integrated terminal in Visual Studio Code.
Well, it turns out the integrated terminal loaded my PATH correctly in the .deb version but not the flatpak one. So... if you, like me, have foolishly installed multiple versions of Visual Studio Code, check which one you are using.
This is what worked for me. I'm not developing in ruby, and don't have a lot of tools that I use it for, so I don't need RVM. I also don't need to install jekyll as root. I just want it to run.
(This answer is just a more descriptive version of answers by Santa Zhang, jayunit100, and a few others.)
1. Find Local Gem Path
> gem env
Assuming this runs, it will list a bunch of useful information. You are looking for GEM PATHS. If there are two, then you want the one that is found in your home directory. Mine was something like /home/<user>/.local/share/gem/ruby/3.0.0
If it doesn't run, install the ruby gem program and try again.
2. Find Gem Binaries Path
Look in that directory until you find the location where the jekyll executable is actually installed. I found it in /home/<user>/.local/share/gem/ruby/3.0.0/bin/jekyll. But what I need is the directory path, not the file, so: /home/<user>/.local/share/gem/ruby/3.0.0/bin/.
3. Add That to PATH
Figure out how to add a directory to your PATH environment variable. Instructions for that are too extensive to provide here, as it depends on your operating system and preferred shell, and the versions of the same. Search for that information elsewhere on Stackoverflow.
4. Restart Your Session
Close your terminal and open a new one. Make sure the directory was added to your path. Depending on how you set your PATH variable, you might need to log out of your session and log in again.

Resources