Command Not Found even after changing path variable - ruby-on-rails

Using heroku for deployment while learning Rails with the Ruby On Rails tutorial by Michael Hartl, on Ubuntu 11.04 Natty Narwhal. I installed it using
sudo gem install heroku
and the commands seemed to run fine for that session in the terminal. The next time I went to work, I tried the command "heroku open" and I was told "heroku: command not found". Looking at some of the answers to similar problems here, it seemed the answer was to run
gem enviroment
which returned the following:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /var/lib/gems/1.8/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /var/lib/gems/1.8
- /home/richard/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
I then ran
$ export PATH=$PATH:/var/lib/gems/1.8/bin
which seemed to fix the problem. However, the next time I tried to run heroku in the terminal, I was told "command not found" again! Running the "export PATH=$PATH" command seems to fix the problem every time, but I would rather I didn't have to run this command everytime I want to use heroku. Is there any permanent solution to the problem?

If you're using bash as your shell, then add that export line to .bash_profile in your home directory. The equivalent for zsh is .zshrc, and other shells have their own files to automatically load for every shell session.

Related

No rails in ubuntu whem i "cd" to project dir

I lose my patience to rails on ubuntu. So far I have used the ready environment on c9, but it is slowly closing. I'm learning how to deal with rails and I have a problem with Ubuntu.
I use tutorials (many) to install it. Finally, I did it, and I created a small project. One page + one model + one controller. Commit, exit, turn off a notebook.
Today when I want to back to programming I opened a terminal and go to project dir /Desktop/Projc/test. And after typed rails s I got the message:
Command 'rails' not found, but can be installed with:
sudo apt install ruby-railties
And what is weird, If I open a terminal in home dir rails are ok. I can create a new project etc. But in the existing project rails "are not installed".
I spent a few hours to look for a solution, reads many posts (so: 10918685, 7788946, 16884034) but nothing help.
I'm afraid that I just did a bigger mess.
Can someone try to help me with my case?
My configs:
gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.1
- RUBY VERSION: 2.6.1 (2019-01-30 patchlevel 33) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/iso/.rvm/gems/ruby-2.6.1
- USER INSTALLATION DIRECTORY: /home/iso/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /home/iso/.rvm/rubies/ruby-2.6.1/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /home/iso/.rvm/gems/ruby-2.6.1/bin
- SPEC CACHE DIRECTORY: /home/iso/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /home/iso/.rvm/rubies/ruby-2.6.1/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/iso/.rvm/gems/ruby-2.6.1
- /home/iso/.rvm/rubies/ruby-2.6.1/lib/ruby/gems/2.6.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /home/iso/.rvm/gems/ruby-2.6.1/bin
- /home/iso/.rvm/gems/ruby-2.6.1#global/bin
- /home/iso/.rvm/rubies/ruby-2.6.1/bin
- /home/iso/.rvm/bin
- /home/iso/.rbenv/plugins/ruby-build/bin
- /home/iso/.rbenv/shims
- /home/iso/.rbenv/bin
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /usr/games
- /usr/local/games
- /snap/bin
echo $PATH:
/home/iso/.rvm/gems/ruby-2.6.1/bin:/home/iso/.rvm/gems/ruby-2.6.1#global/bin:/home/iso/.rvm/rubies/ruby-2.6.1/bin:/home/iso/.rvm/bin:/home/iso/.rbenv/plugins/ruby-build/bin:/home/iso/.rbenv/shims:/home/iso/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
rails -v: 5.2.3
ruby -v: 2.6.0p0
Can someone see a solution? And in the terminal, I have a checked a "run as start shell".

Jenkins uses default ruby but not from RVM

I have Jenkins automation server that connects to my machine through ssh with user snaggs.
My machine has 2 versions of ruby:
default version comes from OS /System/Library/Frameworks/ ..... /usr/bin/ruby
ruby v2.3.3 installed with RVM
On machine the automation runs some Perl script with some commands. whoami from jenkins gives snaggs
When Perl script runs command gem env the output is:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.14.1
- RUBY VERSION: 2.0.0 (2015-12-16 patchlevel 648) [universal.x86_64-darwin16]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-16
- GEM PATHS:
- /Library/Ruby/Gems/2.0.0
- /Users/snaggs/.gem/ruby/2.0.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://rubygems.org"]
- REMOTE SOURCES:
- http://rubygems.org
However when I enter to the same machine with ssh to the same user snaggs I have ruby version installed with rvm:
When I run $ gem env I get output:
RubyGems Environment:
- RUBYGEMS VERSION: 2.6.8
- RUBY VERSION: 2.3.3 (2016-11-21 patchlevel 222) [x86_64-darwin16]
- INSTALLATION DIRECTORY: /Users/snaggs/.rvm/gems/ruby-2.3.3
- USER INSTALLATION DIRECTORY: /Users/snaggs/.gem/ruby/2.3.0
- RUBY EXECUTABLE: /Users/snaggs/.rvm/rubies/ruby-2.3.3/bin/ruby
- EXECUTABLE DIRECTORY: /Users/snaggs/.rvm/gems/ruby-2.3.3/bin
- SPEC CACHE DIRECTORY: /Users/snaggs/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/snaggs/.rvm/rubies/ruby-2.3.3/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-16
- GEM PATHS:
- /Users/snaggs/.rvm/gems/ruby-2.3.3
- /Users/snaggs/.rvm/gems/ruby-2.3.3#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://rubygems.org"]
- REMOTE SOURCES:
- http://rubygems.org
- SHELL PATH:
- /Users/snaggs/.rvm/gems/ruby-2.3.3/bin
- /Users/snaggs/.rvm/gems/ruby-2.3.3#global/bin
- /Users/snaggs/.rvm/rubies/ruby-2.3.3/bin
- /usr/local/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /Users/snaggs/.rvm/bin
How to tell to Jenkins to use other version located under /Users/snaggs/.rvm/gems/ruby-2.3.3?
[EDIT]
I don't run script as super user
I had a similar problem when tried to configure Java version.
Take a look at Jenkins wiki:
When the SSH slaves plugin connects to a slave, it does not run an
interactive shell. Instead, it does the equivalent of your running "ssh
slavehost command..."
So suppose when you will run gem env from ssh, you should get the same result like Jenkins gets: ssh snaggs#1.1.1.1 "gem env"
On machine the automation runs some Perl script with some commands.
You can try to create some custom .bash_profile_CUSTOM that equals to your original .bash_profile You need to call .bash_profile_CUSTOM because Jenkins uses own .bash_profile by default .Run your perl script like:
ssh snaggs#1.1.1.1 "source ~/.bash_profile_CUSTOM && perl some_perl_script.pl"
Just remember that you need to bind bash_profile_CUSTOM file each time Jenkins connects to your build machine. So from Jenkins the command executable should be something like:
source ~/.bash_profile_CUSTOM && perl some_perl_script.pl
let me know if it works or give you different output
Edit: (25/12/2016)
If you don't want to install plugins for Jenkins (like EnvInject Plugin for Prefix Start Slave Command) you can wrap Perl script with bash script, like:
#!/bin/bash
source ~/. bash_profile_CUSTOM;
perl some_perl_script.pl;
So Perl script will start with profile you defined with .bash_profile_CUSTOM.

cap command not found [Cygwin + Capistrano]

I've installed ruby, rubygems and rails through Cygwin setup.
Then I've installed a gem:
gem install capistrano --verbose
No problem here. But when I try to run cap command, Cygwin tells me:cap: command not found
When I execute in ./bin/cap it works:
$ ./bin/cap
Stage not set, please call something such as 'cap production deploy', where production is a stage you have defined.
Here is my gem environment:
$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.1
- RUBY VERSION: 2.0.0 (2014-11-13 patchlevel 598) [i386-cygwin]
- INSTALLATION DIRECTORY: /home/Moretti/.gem/ruby
- RUBY EXECUTABLE: /usr/bin/ruby.exe
- EXECUTABLE DIRECTORY: /home/Moretti/bin
- SPEC CACHE DIRECTORY: /home/Moretti/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /etc
- RUBYGEMS PLATFORMS:
- ruby
- x86-cygwin
- GEM PATHS:
- /home/Moretti/.gem/ruby
- /usr/share/gems
- /usr/local/share/gems
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/bin
- /usr/bin
- /cygdrive/c/Program Files (x86)/Intel/iCLS Client
- /cygdrive/c/Program Files/Intel/iCLS Client
- /cygdrive/c/WINDOWS/system32
- /cygdrive/c/WINDOWS
- /cygdrive/c/WINDOWS/System32/Wbem
- /cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0
- /cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/DAL
- /cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/IPT
- /cygdrive/c/Program Files (x86)/Intel/Intel(R) Management Engine Componen ts/DAL
- /cygdrive/c/Program Files (x86)/Intel/Intel(R) Management Engine Componen ts/IPT
- /usr/bin
The EXECUTABLE DIRECTORY is correct, but the binaries aren't working outside the ~/bin/.
What can I do?
I created a cap file in /usr/local/bin/ and made it executable.
$ cat /usr/local/bin/cap
#!/bin/bash
ruby ~/.gem/ruby/gems/capistrano-3.3.5/bin/cap "$#"
Location of capistrano gem files can be found using gem which capistrano.
I personally do not know if this is the best way of doing it, but I've just set it up yesterday and have managed to get it working for my usecase

How can I get control of gem installation locations?

Lots of confusion and difficulty related to gem installation. My gem environment:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10]
- INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /opt/local/bin/ruby
- EXECUTABLE DIRECTORY: /opt/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-10
- GEM PATHS:
- /opt/local/lib/ruby/gems/1.8
- /Users/apple/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
The problem is one where I will add (eg) to environment.rb :
config.gem 'authlogic'
All good, now when I run
gem install authlogic
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /opt/local/lib/ruby/gems/1.8 directory.
running it with sudo is fine :
Dans-iMac-335:authlogic apple$ sudo rake gems:install
Password:
(in /Users/apple/Documents/projects/authlogic)
gem install authlogic
Successfully installed authlogic-2.1.6
1 gem installed
Installing ri documentation for authlogic-2.1.6...
Installing RDoc documentation for authlogic-2.1.6...
but running rake tasks throws an error :
Dans-iMac-335:authlogic apple$ rake db:migrate
(in /Users/apple/Documents/projects/authlogic)
Missing these required gems:
authlogic
You're running:
ruby 1.8.7.174 at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
rubygems 1.3.5 at /Users/apple/.gem/ruby/1.8, /Library/Ruby/Gems/1.8, /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
Run `rake gems:install` to install the missing gems.
I can't see what the problem is. And I'm going out of my mind. The directory at the 'other' gems location :
Dans-iMac-335:authlogic apple$ ls /Users/apple/.gem/ruby/1.8/gems
actionmailer-2.2.2 activeresource-2.2.2 aws-s3-0.6.2 mysql-2.8.1 rails-2.2.2 xml-simple-1.0.12
actionpack-2.2.2 activeresource-2.3.3 builder-2.1.2 packet-0.1.15 rake-0.8.7
actionwebservice-1.2.3 activesupport-2.2.2 chronic-0.2.3 pg-0.8.0 rest-client-1.3.1
activerecord-2.2.2 activesupport-2.3.3 mime-types-1.16 rack-1.0.0 sqlite3-ruby-1.0.1
activerecord-2.3.5 activesupport-2.3.5 mongrel-1.1.5 rack-1.0.1 taps-0.2.26
This, I assume, is the default OSX rails system? The first location gives the much fuller set that represents my normal environment. Since my projects depend on many of these, and they aren't present in the other directory, this is verifiably the location that gems are being pulled from in my development environment:
Dans-iMac-335:authlogic apple$ ls /opt/local/lib/ruby/gems/1.8/gems
RedCloth-4.2.3 crack-0.1.8 mime-types-1.16 rack-1.1.0 sinatra-0.9.2
actionmailer-2.3.5 daemons-1.0.10 minitest-1.4.2 radiant-0.8.1 sinatra-1.0
actionmailer-2.3.8 faker-0.3.1 mogli-0.0.14 rails-2.2.2 spree-0.10.2
actionpack-2.3.5 fastthread-1.0.7 mongrel-1.1.5 rails-2.3.5 sqlite3-ruby-1.0.1
actionpack-2.3.8 gem_plugin-0.2.3 mutter-0.5.3 rails-2.3.8 sqlite3-ruby-1.2.5
activemerchant-1.5.1 google-geocode-1.2.1 mysql-2.8.1 rc-rest-3.0.0 state_machine-0.8.0
activerecord-2.3.8 hashie-0.4.0 net-scp-1.0.2 rest-client-1.0.3 stringex-1.0.3
activerecord-tableless-0.1.0 heroku-1.10.8 net-sftp-2.0.2 rest-client-1.6.1 taps-0.2.19
activeresource-2.3.5 highline-1.5.1 net-ssh-2.0.15 rmagick-2.13.1 taps-0.3.13
activeresource-2.3.8 hoe-2.3.3 net-ssh-gateway-1.0.1 ruby-hmac-0.4.0 thor-0.9.9
activesupport-2.3.8 hpricot-0.8.1 nokogiri-1.3.3 ruby-openid-2.1.7 treetop-1.4.8
authlogic-2.1.6 httparty-0.6.1 paperclip-2.3.1.1 rubyforge-2.0.2 whenever-0.3.7
authlogic-oid-1.0.4 json-1.1.9 passenger-2.2.5 rubyforge-2.0.4 will_paginate-2.3.11
aws-s3-0.6.2 json_pure-1.1.9 pg-0.8.0 rubygems-update-1.3.5 xml-simple-1.0.12
builder-2.1.2 json_pure-1.2.4 pg-0.9.0 rubygems-update-1.3.7
capistrano-2.5.9 launchy-0.3.3 polyglot-0.3.1 searchlogic-2.3.5
cgi_multipart_eof_fix-2.5.0 less-1.2.20 postgres-0.7.9.2008.01.28 sequel-3.0.0
configuration-1.1.0 libxml-ruby-1.1.3 rack-1.0.1 sequel-3.15.0
So, if the system uses this /opt/local/lib/ruby/gems/1.8/gems directory, why can't it see it when I call rake? And what can I do about it?
I don't see what the problem is, but have you tried running "gem list " to see what gems your system recognizes as having installed?
My solution was to change the #! line of rake.rb to point to the location of the ruby installation that has the gems.
From what I learned, when you're installing gems, rails takes account of the $PATH variable, but when loading the environment when rake is called, it doesn't. So rake doesn't know about those locations. The answer, then, was to direct rake's attention to the right location.

Rubygems. LoadError in Rails

Everytime I start my Rails applications I get LoadError with the following output.
On Rails 2.3.8:
no such file to load -- sqlite3/sqlite3_native
<internal:lib/rubygems/custom_require>:29:in `require'
On Rails 3.0.0:
no such file to load -- bundler
<internal:lib/rubygems/custom_require>:29:in `require'
I run the applications in the production mode on a development machine using Nginx + Passenger.
What is the reason of this issue? How can I solve it?
Thanks.
Debian GNU/Linux 5.0.6;
Ruby 1.9.2;
Rubygems 1.3.7;
Ruby on Rails 2.3.8, 3.0.0;
Nginx 0.8.50;
Passenger 2.2.15;
sqlite3-ruby 1.3.1;
bundler 1.0.0.rc.6.
Updated
All of my gems is installed by the unprivileged user in the local directory /home/<usernam>/.gem. If it helps, here's the gem env output:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [i686-linux]
- INSTALLATION DIRECTORY: /home/<username>/.gem
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /home/<username>/.gem/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/<username>/.gem
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "--no-ri --no-rdoc"
- :gemhome => "/home/<username>/.gem"
- :gempath => ["/home/<username>/.gem"]
- REMOTE SOURCES:
- http://rubygems.org/
Updated
I tackled with the problem. Its source was that I defined a custom gem path. That is I added to the ~/.gemrc file the following lines:
:gemhome: /home/<username>/.gem
:gempaths:
- /home/<username>/.gem
Thus all of my gems was placed in the specified directory but not the default one. For some reason Rubygems coundn't find it there and rose an exception.
When I removed that lines from the file the default paths was set for Rubygems and after I installed all the required gems and loaded my Rails applications all began to work.
Once again, the bug conditions are:
Nginx + Passenger;
The gempath is set to /home/<unprivileged_user>/.gem in ~/.gemrc;
An init.d script is creaded and added to the boot sequence (update-rc.d nginx defaults);
System is rebooted, server is started atomaticlally;
http://localhost/my_rails_app;
LoadError; no such file to load -- <gem_name>; <internal:lib/rubygems/custom_require>:29:in `require'.
Why can't Rubygems find gems in the custom location but can find them in default? That's the question.
I too had this problem when using RVM - I must have specified a gemset or something and not made it project specific. At any rate, read this rvm guide if you want to know the basics of RVM and try to specify a new gemset for your current folder / project, install a new rails gem to that gemset, and then use that gemset. For example, to create a new gemset for rails version 2.3.8:
$ rvm gemset create rails238
$ rvm ruby-1.8.7#rails238
$ gem install rails -v 2.3.8
Then if all went according to plan type rvm gemset use [gemsetName], or do rvm gemset list to see a list of installed gemsets, and to see if rails is working fine try rails -v and you should see rails 2.3.8
Check your system to locate where your rubies and gems are installed ( you can do this by "which ruby" and "which gem"). Usually, they're installed in the same folder (/usr/bin or /usr/local). If they are in different locations, there might be load error. Just a suggestion.

Resources