Ubuntu

嘗試以 sudo 執行 rvm 命令時出現“找不到命令”

  • May 30, 2017

我正在嘗試在我的 Ubuntu 14.04 機器上重新安裝 Ruby,但我對如何設置 PATH 變數或其他東西感到困惑。當我以普通使用者身份嘗試時,我會收到各種 Permission denied 錯誤….

myuser@myproject:~$ rvm reinstall ruby-2.4.0
mkdir: cannot create directory ‘/usr/local/rvm/log/1496156193_ruby-2.4.0’: Permission denied
tee: /usr/local/rvm/log/1496156193_ruby-2.4.0/remove.rubies.log: No such file or directory
ruby-2.4.0 - #removing rubies/ruby-2.4.0....
Error running '__rvm_rm_rf /usr/local/rvm/rubies/ruby-2.4.0',
showing last 15 lines of /usr/local/rvm/log/1496156193_ruby-2.4.0/remove.rubies.log
tail: cannot open ‘/usr/local/rvm/log/1496156193_ruby-2.4.0/remove.rubies.log’ for reading: No such file or directory
mkdir: cannot create directory ‘/usr/local/rvm/log/1496156193_ruby-2.4.0’: Permission denied
tee: /usr/local/rvm/log/1496156193_ruby-2.4.0/remove.rubies.log: No such file or directory
ruby-2.4.0 - #removing rubies/ruby-2.4.0....
Error running '__rvm_rm_rf /usr/local/rvm/rubies/ruby-2.4.0',
showing last 15 lines of /usr/local/rvm/log/1496156193_ruby-2.4.0/remove.rubies.log
tail: cannot open ‘/usr/local/rvm/log/1496156193_ruby-2.4.0/remove.rubies.log’ for reading: No such file or directory
Searching for binary rubies, this might take some time.
Found remote file https://rubies.travis-ci.org/ubuntu/14.04/x86_64/ruby-2.4.0.tar.bz2
Checking requirements for ubuntu.
Requirements installation successful.
ruby-2.4.0 - #configure
ruby-2.4.0 - #download
ruby-2.4.0 - #validate archive
ruby-2.4.0 - #extract
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/README.md’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/.travis.yml’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/test/dtf/rubygems_comment_test.sh’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/test/dtf/binary_comment_test.sh’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/test/dtf/bundler_comment_test.sh’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/test/dtf/rails_and_gemfile_comment_test.sh’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/CHANGELOG.md’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/LICENSE’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/rubygems-bundler.gemspec’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/lib/rubygems_executable_plugin.rb’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/version.rb’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/Gemfile’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/.noexec.yaml’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/.gem.config’: Permission denied
rm: cannot remove ‘/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/rubygems-bundler-1.4.4/.gitignore’: Permission denied
mktemp: failed to create directory via template ‘/usr/local/rvm/tmp/rvm-tmp.XXXXXXXXX’: Permission denied
mkdir: cannot create directory ‘’: No such file or directory
tar: : Cannot open: No such file or directory

但是當我以 sudo 身份安裝並安裝時,我收到“找不到命令”錯誤

myuser@myproject:~$ sudo rvm reinstall ruby-2.4.0
sudo: rvm: command not found

如何設置我的 sudo 以便它像普通使用者一樣找到我的 rvm 執行檔?

試試sudo -E rvm reinstall ruby-2.4.0

來自man sudo

-E, –preserve-env

向安全策略指示使用者希望保留其現有環境變數。如果使用者沒有保護環境的權限,安全策略可能會返回錯誤。

引用自:https://unix.stackexchange.com/questions/368130