我正在尝试在 Ubuntu 14.04 机器上重新安装 Ruby,但我对如何设置 PATH 变量或其他内容感到困惑。当我以普通用户身份尝试时,我收到各种权限被拒绝的错误......
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
但是当我 tyr 并安装为 sudo 时,我收到“命令未找到”错误
myuser@myproject:~$ sudo rvm reinstall ruby-2.4.0
sudo: rvm: command not found
如何设置 sudo 以便它像普通用户一样找到我的 rvm 可执行文件?
答案1
尝试sudo -E rvm reinstall ruby-2.4.0
。
从man sudo
:
-E, --preserve-env
向安全策略表明用户希望保留其现有的环境变量。如果用户没有保护环境的权限,安全策略可能会返回错误。