如何在 Ubuntu 上安装“colorls”?

如何在 Ubuntu 上安装“colorls”?

我想安装色彩. 看起来很方便:

截屏

我尝试跟随安装说明。然而,它们似乎不是为 Ubuntu 制作的。

首先,因为gem不存在,所以我必须逃跑sudo apt install ruby-rubygems

现在,当我尝试安装它时遇到此错误:

$ gem install colorls
Fetching colorls-1.4.6.gem
...
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /var/lib/gems/3.0.0 directory.

所以我尝试使用--user-install标志:

$ gem install --user-install colorls
WARNING:  You don't have /home/flimm/.local/share/gem/ruby/3.0.0/bin in your PATH,
      gem executables will not run.
Successfully installed unicode-display_width-2.4.2
Successfully installed rainbow-3.1.1
Successfully installed manpages-0.6.1
Successfully installed filesize-0.2.0
Building native extensions. This could take a while...
ERROR:  Error installing colorls:
    ERROR: Failed to build gem native extension.

    current directory: /home/flimm/.local/share/gem/ruby/3.0.0/gems/clocale-0.0.4/ext/clocale
/usr/bin/ruby3.0 -I /usr/lib/ruby/vendor_ruby -r ./siteconf20230407-19626-voy41j.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.

extconf failed, exit code 1

Gem files will remain installed in /home/flimm/.local/share/gem/ruby/3.0.0/gems/clocale-0.0.4 for inspection.
Results logged to /home/flimm/.local/share/gem/ruby/3.0.0/extensions/x86_64-linux/3.0.0/clocale-0.0.4/gem_make.out

如何在 Ubuntu 上安装(和卸载)colorls?

答案1

  1. 安装带有开发标头的 Ruby Gem:

    sudo apt install ruby-rubygems ruby-dev
    
  2. 下载并安装 Nerd 字体(需要安装才能正确显示漂亮的图标)。打开下载的存档文件,打开每个字体文件,然后单击“安装”按钮:

    截图

  3. 设置你的终端以使用该字体。(此步骤可能不需要)

  4. 安装colorls

     $ gem install --user-install colorls
     WARNING:  You don't have /home/flimm/.local/share/gem/ruby/3.0.0/bin in your PATH,
           gem executables will not run.
     ...
    
  5. 如果前面的命令警告您路径中没有正确的位置,请修改~/.bashrc(或在您最喜欢的 shell 中进行等效操作)以添加此行,以修改您的 PATH:

     PATH="$PATH:$HOME/.local/share/gem/ruby/3.0.0/bin"
    
  6. 要添加制表符补全,请将这一行添加到~/.bashrc(或在您最喜欢的 shell 中添加等效行):

     source $(dirname $(gem which colorls))/tab_complete.sh
    
  7. 现在重启你的终端。你现在就可以运行了colorls,新字体也会生效。

要卸载 colorls,请运行gem uninstall colorls并删除 中添加的行~/.bashrc。您可能还想撤消依赖项的安装。

相关内容