Why is sudo: bundle command not found?
Check if the PATH
has the same values both with and without sudo
. Apparently it cannot find bundle
just because it is not listed in PATH
You can compare the outputs of following two lines
$ echo 'echo $PATH' | sh
$ echo 'echo $PATH' | sudo sh
Ideally sudo
is supposed to leave PATH
untouched. But this might be a side issue of your hosting distribution.
Edit by original poster. Output is:
[root@desktop etc]# echo 'echo $PATH' | sh
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@desktop etc]# echo 'echo $PATH' | sudo sh
/sbin:/bin:/usr/sbin:/usr/bin:/user/local/bin
[root@desktop etc]#
Using $ sudo bundle exec ... raises 'bundle: command not found' error
Dan Carley's rbenv-sudo looks like it will do what you want:
rbenv-sudo is a plugin for rbenv that allows you to run rbenv-provided Rubies and Gems from within a sudo session.
A more detailed explanation of how it works is provided in this article: Sudo Rbenv Me a Sandwich
sudo bundle causes `could not find bundler` error
In order to use bundle
command, you need to install bundler
first:
sudo gem install bundler
Then you will be able to use bundle
command:
sudo bundle exec . . .
Checkout bundler official page for more information.
bash: bundle: command not found - cap aborted
Here is what I have now which resolved the issue. I got help from Rustam A. Gasanov to make it working. Thanks a lot!!
deploy.rb
# config valid only for current version of Capistrano
lock '3.4.0'
set :stage, 'production'
set :application, "gobgob-ror"
set :repo_url, 'git@github.com:narhamah/gobgob-ror.git'
set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.2.2@gobgob'
set :rvm_binary, '~/.rvm/bin/rvm'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/home/ubuntu/gobgob-ror'
# Default value for :scm is :git
set :scm, :git
set :branch, "master"
#set :user, "ubuntu"
set :use_sudo, false
set :rails_env, "production"
set :deploy_via, :remote_cache
set :ssh_options, { user: 'ubuntu', :forward_agent => true, :port => 22, keys: ["#{ENV['HOME']}/.ssh/id_rsa"]}
# Default value for :format is :pretty
# set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
set :pty, true
server "xx.xx.xxx.xxx", roles: [:app, :web, :db], :primary => true
set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets}
# Default value for :linked_files is []
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for keep_releases is 5
set :keep_releases, 5
namespace :deploy do
desc "Start the application"
task :start do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{fetch(:stage)}.log 2>&1 &", :pty => false
end
end
desc "Stop the application"
task :stop do
on roles => :app do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state stop"
end
end
desc "Restart the application"
task :restart do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state restart"
end
end
desc "Status of the application"
task :status do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state stats"
end
end
end
after "deploy", "deploy:restart"
after "deploy", "deploy:cleanup"
Last output which confirmed it works..
INFO [12d4a428] Running /usr/bin/env cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.2.2@gobgob do bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart on xx.xx.xxx.xxx
DEBUG [12d4a428] Command: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.2.2@gobgob do bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart
DEBUG [12d4a428] Command restart sent success
DEBUG [12d4a428]
INFO [12d4a428] Finished in 1.379 seconds with exit status 0 (successful).
[arup@gobgob-ror (master)]$
Rails - Bundle: command not found
It seems that Bundler is not installed in your machine.
You have to install bundler first for that.
1: gem install bundler
2: bundle install
Hope this help you !!!
bundle install - command not found - running as root
I added /usr/local/bin
and /usr/local/sbin
to secure_path in /etc/sudoers
sudo visudo
Then change this line:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
Changed this to
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
Explanation:
Gems were installed at /usr/local path and without adding this in secure_path, root user cannot run scripts from there. You can check your gems path by running gem env
in shell.
I also had another issue. I installed gems as ec2-user using bundle and default rubygems path in Amazon Linux installed them only for ec2-user, something I did not like so I installed ruby and rubygems from source which has path to installed them at central location under /usr/local. I know it is not recommended by many but I like it this way. By the way, I tried to find a way to change rubygems path but I could not.
How to fix sudo bundle install
From Bundler's documentation:
By default, Bundler installs gems to the same location as gem install.
In some cases, that location may not be writable by your Unix user. In that case, >Bundler will stage everything in a temporary directory, then ask you for your >sudo password in order to copy the gems into their system location.
From your perspective, this is identical to installing the gems directly into the >system.
You should never use sudo bundle install. This is because several other steps in >bundle install must be performed as the current user:
Updating your Gemfile.lock
Updating your vendor/cache, if necessary
Checking out private git repositories using your user's SSH keys
Of these three, the first two could theoretically be performed by chowning the >resulting files to $SUDO_USER. The third, however, can only be performed by >invoking the git command as the current user. Therefore, git gems are downloaded >and installed into ~/.bundle rather than $GEM_HOME or $BUNDLE_PATH.
As a result, you should run bundle install as the current user, and Bundler will >ask for your password if it is needed to put the gems into their final location.
As a possible solution you can fully uninstall Ruby and its dependencies, and then install Ruby using asdf, RVM or rbenv and run Bundler again.
I use Bundler just to install gems from a gemfile. cd
into the project with the gemfile and run bundle install
. It must find the gemfile and install the gems automatically. I think it's bad to use Bundler inside the home directory.
I have all gems installed here:
~/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems
bundle command not found in linux debian
gem install bundler
or probably, since there is an executable
sudo gem install bundler
Related Topics
Convert Time from One Time Zone to Another in Rails
Nokogiri Gem Installation Error
Eoferror: End of File Reached Issue With Net::Http
To Use Self. or Not.. in Rails
Ruby/Rails - Change the Timezone of a Time, Without Changing the Value
Undefined Method 'Visit' When Using Rspec and Capybara in Rails
Difference Between $Stdout and Stdout in Ruby
How to Read Lines of a File in Ruby
Ruby: Easiest Way to Filter Hash Keys
How to Do Static Content in Rails
How to Get Filename Without Extension from File Path in Ruby
How to Create a Sha1 Hash in Ruby
How to Get Ruby/Homebrew/Rvm to Work on Yosemite
What Does Class_Eval ≪≪-"End_Eval", _File_, _Line_ Mean in Ruby
Why Are Methods in Ruby Documentation Preceded by a Hash Sign
Why Are My Basic Heroku Apps Taking Two Seconds to Load
Get Current Stack Trace in Ruby Without Raising an Exception