首页 > 解决方案 > Ghostscript 已安装但未找到 RGhost::Config::GS[:path]='/path/to/my/gs'

问题描述

我已经尝试了几个小时来解决这个问题,我到处寻找解决方案,但没有找到。我正在尝试为我的项目运行规范测试,但出现以下错误:

RuntimeError:
 
   Ghostscript not found in your system environment (linux-gnu).
   Install it and set the variable RGhost::Config::GS[:path] with the executable.
   Example: RGhost::Config::GS[:path]='/path/to/my/gs' #unix-style
    RGhost::Config::GS[:path]="C:\\gs\\bin\\gswin32c.exe"  #windows-style

我确实尝试输入RGhost::Config::GS[:path]='/usr/local/bin/gs'并返回:

bash: RGhost::Config::GS[:path]=/usr/local/bin/gs: No such file or directory

但是安装了ghostscript,我做了所有事情(make,sudo make install等),当我运行gs -v它时返回:

GPL Ghostscript 9.26 (2018-11-20)
Copyright (C) 2018 Artifex Software, Inc.  All rights reserved.

当我使用用户界面并在“文件”应用程序中搜索“gs”时,可以找到它/home/marcelle/projects/ghostscript-9.26/bin/gs并且我也尝试过:

RGhost::Config::GS[:path]='/home/marcelle/projects/ghostscript-9.26/bin/gs'

它返回相同的错误:

bash: RGhost::Config::GS[:path]=/home/marcelle/projects/ghostscript-9.26/bin/gs: No such file or directory

我还尝试使用 autoremove 和 purge 从我的笔记本中删除 ghostscript,然后使用我之前提到的(./configure、make、sudo make install)重新安装它,重新启动笔记本、终端,什么也没有。

PS:我使用的是 Ubuntu 20.04。

标签: ruby-on-railsrubyruby-on-rails-5runtime-errorghostscript

解决方案


我设法想出了一个解决方案。寻找 Rghost 的代码,我在其规范中看到的是预期的路径与 ghostscript 的实际路径不同。当我在终端上运行 whereis 或 which 时,它会返回:

which gs
/usr/local/bin/gs

所以我试图指出这条路。但是看到我在github 上为 Rghost找到的 Rghost 规范测试,我们可以看到它需要 /usr/bin/gs:

 it 'should detect linux env properly' do
    RbConfig::CONFIG.should_receive(:[]).twice.with('host_os').and_return('linux')
    File.should_receive(:exists?).with('/usr/bin/gs').and_return(true)
    RGhost::Config.config_platform
    RGhost::Config::GS[:path].should == '/usr/bin/gs'
  end

所以它需要 /usr/bin 而不是 /usr/local/bin。然后我只是复制到那个路径并且规范运行没有问题了:

sudo cp /usr/local/bin/gs /usr/bin

推荐阅读