You don’t have write permissions for the /usr/bin directory. when I installing some package with gem

投稿者: | 2019年2月5日

When you get “You don’t have write permissions for the /usr/bin directory”

in your installation with gem, you can solve the issue with the option -n /usr/local/bin.

Many internet sources said so. Of cource it works.

I thought this is a good chance to look a little more about gem install options.

We can get the information by ‘gem help install’ in the terminal.

Several useful options

I found several useful options in the help document as follows.

install command options

-v, --version VERSION: Specify version of gem to install

    --[no-]prerelease: Allow prerelease versions of a gem to be installed. (Only for listed gems)

-i, --install-dir: DIR Gem repository directory to get installed gems

-n, --bindir DIR: Directory where executables are located

common options

-h, --help: Get help on this command (same as gem help command)
-V, --[no-]verbose: Set the verbose level of output
-q, --quiet: Silence command progress meter
    --silent: Silence RubyGems output
    --config-file FILE: Use this config file instead of default (maybe useful for the batch-like jobs)
    --backtrace: Show stack backtrace on errors

コメントを残す

macOSでgemを使ってインストールする際のトラブル対策:You don’t have write permissions …

投稿者: | 2019年2月5日

You don’t have write permissions for the /usr/bin directory.といわれたら

macOSにおいてgemでいろんなユーティリティソフトをインストールする際に出くわすことがあるらしい。

解決策はオプション -n /usr/local/bin を付けよ、というものであるが、この機会にgem installについて調べておく。

gem installのオプション

まずこれを知るためにはHelpドキュメントを読まなくてはならない。特定のコマンドに関するヘルプを得るにはgem help commandとする。今回はinstallなので

$ gem help install

とすればよい。全文は後で記すとして-n, –bindir DIRは”Directory where executables are located”ということなので実行ファイルをどこに置くかを指定するためのオプションだった。

他の使えそうなオプション

全文の中にある(installコマンドの)オプションからいくつか使えそうなものを持ってきた。

-v, –version VERSION:特定のバージョンのGemをインストールする
-i, –install-dir DIR:Gemのリポジトリをインストールするディレクトリを指定する
–[no-]prerelease:プリリリースのGemを入れたり、入れなかったりを指定する

共通オプションの中にも

-h, –help:このコマンドに対するヘルプを取得。gem help commandと同じ
-V, –[no-]verbose:出力を饒舌にするか、否か
-q, –quiet:コマンド進行のメーターを出さない
–silent:RubyGems出力を出さない
–config-file FILE:コンフィグファイルを使う(複数台で同じ事をやるには良さそう)
–backtrace:エラーのバックトレースを見せる

という便利そうなものがある。

gem installのヘルプドキュメント全文

$ gem help install
Usage: gem install GEMNAME [GEMNAME ...] [options] -- --build-flags [options]

  Options:
        --platform PLATFORM          Specify the platform of gem to install
    -v, --version VERSION            Specify version of gem to install
        --[no-]prerelease            Allow prerelease versions of a gem
                                     to be installed. (Only for listed gems)


  Deprecated Options:
        --[no-]rdoc                  Generate RDoc for installed gems
                                     Use --document instead
        --[no-]ri                    Generate ri data for installed gems.
                                     Use --document instead
    -u, --[no-]update-sources        Update local source cache


  Install/Update Options:
    -i, --install-dir DIR            Gem repository directory to get installed
                                     gems
    -n, --bindir DIR                 Directory where executables are
                                     located
        --[no-]document [TYPES]      Generate documentation for installed gems
                                     List the documentation types you wish to
                                     generate.  For example: rdoc,ri
        --build-root DIR             Temporary installation root. Useful for building
                                     packages. Do not use this when installing remote gems.
        --vendor                     Install gem into the vendor directory.
                                     Only for use by gem repackagers.
    -N, --no-document                Disable documentation generation
    -E, --[no-]env-shebang           Rewrite the shebang line on installed
                                     scripts to use /usr/bin/env
    -f, --[no-]force                 Force gem to install, bypassing dependency
                                     checks
    -w, --[no-]wrappers              Use bin wrappers for executables
                                     Not available on dosish platforms
    -P, --trust-policy POLICY        Specify gem trust policy
        --ignore-dependencies        Do not install any required dependent gems
        --[no-]format-executable     Make installed executable names match Ruby.
                                     If Ruby is ruby18, foo_exec will be
                                     foo_exec18
        --[no-]user-install          Install in user's home directory instead
                                     of GEM_HOME.
        --development                Install additional development
                                     dependencies
        --development-all            Install development dependencies for all
                                     gems (including dev deps themselves)
        --conservative               Don't attempt to upgrade gems already
                                     meeting version requirement
        --minimal-deps               Don't upgrade any dependencies that already
                                     meet version requirements
        --[no-]post-install-message  Print post install message
    -g, --file [FILE]                Read from a gem dependencies API file and
                                     install the listed gems
        --without GROUPS             Omit the named groups (comma separated)
                                     when installing from a gem dependencies
                                     file
        --default                    Add the gem's full specification to
                                     specifications/default and extract only its bin
        --explain                    Rather than install the gems, indicate which would
                                     be installed
        --[no-]lock                  Create a lock file (when used with -g/--file)
        --[no-]suggestions           Suggest alternates when gems are not found


  Local/Remote Options:
    -l, --local                      Restrict operations to the LOCAL domain
    -r, --remote                     Restrict operations to the REMOTE domain
    -b, --both                       Allow LOCAL and REMOTE operations
    -B, --bulk-threshold COUNT       Threshold for switching to bulk
                                     synchronization (default 1000)
        --clear-sources              Clear the gem sources
    -s, --source URL                 Append URL to list of remote gem sources
    -p, --[no-]http-proxy [URL]      Use HTTP proxy for remote operations


  Common Options:
    -h, --help                       Get help on this command
    -V, --[no-]verbose               Set the verbose level of output
    -q, --quiet                      Silence command progress meter
        --silent                     Silence RubyGems output
        --config-file FILE           Use this config file instead of default
        --backtrace                  Show stack backtrace on errors
        --debug                      Turn on Ruby debugging
        --norc                       Avoid loading any .gemrc file


  Arguments:
    GEMNAME       name of gem to install

  Summary:
    Install a gem into the local repository

  Description:
    The install command installs local or remote gem into a gem repository.

    For gems with executables ruby installs a wrapper file into the executable
    directory by default.  This can be overridden with the --no-wrappers option.
    The wrapper allows you to choose among alternate gem versions using
    _version_.

    For example `rake _0.7.3_ --version` will run rake version 0.7.3 if a newer
    version is also installed.

    Gem Dependency Files
    ====================

    RubyGems can install a consistent set of gems across multiple environments
    using `gem install -g` when a gem dependencies file (gem.deps.rb, Gemfile or
    Isolate) is present.  If no explicit file is given RubyGems attempts to find
    one in the current directory.

    When the RUBYGEMS_GEMDEPS environment variable is set to a gem dependencies
    file the gems from that file will be activated at startup time.  Set it to a
    specific filename or to "-" to have RubyGems automatically discover the gem
    dependencies file by walking up from the current directory.

    NOTE: Enabling automatic discovery on multiuser systems can lead to
    execution of arbitrary code when used from directories outside your control.

    Extension Install Failures
    ==========================

    If an extension fails to compile during gem installation the gem
    specification is not written out, but the gem remains unpacked in the
    repository.  You may need to specify the path to the library's headers and
    libraries to continue.  You can do this by adding a -- between RubyGems'
    options and the extension's build options:

      $ gem install some_extension_gem
      [build fails]
      Gem files will remain installed in \
      /path/to/gems/some_extension_gem-1.0 for inspection.
      Results logged to /path/to/gems/some_extension_gem-1.0/gem_make.out
      $ gem install some_extension_gem -- --with-extension-lib=/path/to/lib
      [build succeeds]
      $ gem list some_extension_gem

      *** LOCAL GEMS ***

      some_extension_gem (1.0)
      $

    If you correct the compilation errors by editing the gem files you will need
    to write the specification by hand.  For example:

      $ gem install some_extension_gem
      [build fails]
      Gem files will remain installed in \
      /path/to/gems/some_extension_gem-1.0 for inspection.
      Results logged to /path/to/gems/some_extension_gem-1.0/gem_make.out
      $ [cd /path/to/gems/some_extension_gem-1.0]
      $ [edit files or what-have-you and run make]
      $ gem spec ../../cache/some_extension_gem-1.0.gem --ruby > \
                 ../../specifications/some_extension_gem-1.0.gemspec
      $ gem list some_extension_gem

      *** LOCAL GEMS ***

      some_extension_gem (1.0)
      $

    Command Alias
    ==========================

    You can use `i` command instead of `install`.

      $ gem i GEMNAME

  Defaults:
    --both --version '>= 0' --document --no-force
    --install-dir /Library/Ruby/Gems/2.3.0 --lock

コメントを残す