如何在 bash 上添加/设置 Ruby 路径



我在安装 wp-scan 时遇到问题,特别是使用以下命令:

sudo gem install bundler && bundle install --without test

返回:

WARNING:  You don't have /root/.gem/ruby/2.3.0/bin in your PATH, 
  gem executables will not run.
 Successfully installed bundler-1.12.4
 Parsing documentation for bundler-1.12.4
 Done installing documentation for bundler after 5 seconds
 1 gem installed
 bash: bundle: command not found

我搜索了一下,似乎我没有设置 Ruby 路径,但是当我尝试使用"设置"设置它时,bash 返回:

-e:1: unexpected fraction part after numeric literal
/root/.gem/ruby/2.3.0/
                  ^

这是 .bashrc 文件:

#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
PS1='[u@h W]$ '
# >>>>BEGIN ADDED BY CNCHI INSTALLER<<<< #
BROWSER=/usr/bin/chromium
EDITOR=/usr/bin/nano
# >>>>>END ADDED BY CNCHI INSTALLER<<<<< #
#la riga inferiore serve a creare il path corretto di gem /ruby
PATH="$(ruby -e '/root/.gem/ruby/2.3.0/')/bin:$PATH"

我做错了什么?

这是宝石环境返回:

RubyGems Environment: - RUBYGEMS VERSION: 2.5.1 - RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-linux] - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/2.3.0 - USER INSTALLATION DIRECTORY: /home/thecave3/.gem/ruby/2.3.0 - RUBY EXECUTABLE: /usr/bin/ruby - EXECUTABLE DIRECTORY: /usr/bin - SPEC CACHE DIRECTORY: /home/thecave3/.gem/specs - SYSTEM CONFIGURATION DIRECTORY: /etc - RUBYGEMS PLATFORMS: - ruby - x86_64-linux - GEM PATHS: - /usr/lib/ruby/gems/2.3.0 - /home/thecave3/.gem/ruby/2.3.0 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :backtrace => false - :bulk_threshold => 1000 - "gem" => "--user-install" - REMOTE SOURCES: - https://rubygems.org/ - SHELL PATH: - /usr/local/sbin - /usr/local/bin - /usr/bin - /usr/bin/site_perl - /usr/bin/vendor_perl - /usr/bin/core_perl - /root/.gem/ruby/2.3.0/bin

将以下内容添加到您的.bashrc应该可以解决问题:

export PATH="$PATH:/root/.gem/ruby/2.3.0/bin"

$(..)是命令替换,它是一种从命令捕获输出的方法:

a=$(echo 1234)

会将值1234分配给a,当然,a=1234也可以实现相同的目标。

ruby -e '...'

将评估-e之后传递的代码,在您的情况下/root/.gem/ruby/2.3.0/这不是有效的 Ruby 代码,而是查找可执行文件的路径。

我还在 PATH 变量的末尾添加了 Ruby 路径。这被认为是最好的方法,因为 shell 会搜索它以找到所需的程序。考虑一下:

~/bin % export PATH="$HOME/bin:/bin:/usr/bin" 
~/bin % cat grep
#!/bin/sh
echo "got ya"
~/bin % grep '...' '...'
got ya

相关内容

  • 没有找到相关文章

最新更新