"require" 需要时找不到命令 'nokogiri'
"require" command not found when require 'nokogiri'
Homebrew,ruby 2.0.0p648,nokogiri 1.6.7.2 已安装。 require 'nokogiri' 时出现错误:
-bash: require: command not found
怎么了?
您是 运行 您在 bash 中的命令 -- 这是一个 Ruby 命令。
像这样从 console/terminal shell 中尝试 运行ning 脚本:
ruby script_name.rb
您也可以尝试将此 shebang line 添加到 .rb 文件的顶部:
#!/usr/bin/env ruby
当您尝试在某些 shell 中直接 运行 时,这会将脚本自动识别为 Ruby。另见:
- Why is it better to use “#!/usr/bin/env NAME” instead of “#!/path/to/NAME” as my shebang?
- what is the use of “#!/usr/local/bin/ruby -w” at the start of a ruby program
您不能在 bash 中直接 运行 Ruby 命令。如果你想在命令行使用 Ruby,打开 Ruby shell irb.
$ irb
然后你会看到提示
2.3.0 :001 >
第一个数字表示您正在使用的 Ruby 版本。在我的例子中是 Ruby 2.3.0。第二个数字是命令号。
然后你可以输入
require 'nokogiri'
如果你安装了这个gem,它肯定可以工作。
Homebrew,ruby 2.0.0p648,nokogiri 1.6.7.2 已安装。 require 'nokogiri' 时出现错误:
-bash: require: command not found
怎么了?
您是 运行 您在 bash 中的命令 -- 这是一个 Ruby 命令。
像这样从 console/terminal shell 中尝试 运行ning 脚本:
ruby script_name.rb
您也可以尝试将此 shebang line 添加到 .rb 文件的顶部:
#!/usr/bin/env ruby
当您尝试在某些 shell 中直接 运行 时,这会将脚本自动识别为 Ruby。另见:
- Why is it better to use “#!/usr/bin/env NAME” instead of “#!/path/to/NAME” as my shebang?
- what is the use of “#!/usr/local/bin/ruby -w” at the start of a ruby program
您不能在 bash 中直接 运行 Ruby 命令。如果你想在命令行使用 Ruby,打开 Ruby shell irb.
$ irb
然后你会看到提示
2.3.0 :001 >
第一个数字表示您正在使用的 Ruby 版本。在我的例子中是 Ruby 2.3.0。第二个数字是命令号。
然后你可以输入
require 'nokogiri'
如果你安装了这个gem,它肯定可以工作。