4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

何もしてないのにrustcとcargoのPATHが通っていた話

Last updated at Posted at 2024-10-01

これは何?

rustの環境構築していたら.zshrcや.bashrcの設定なしに$HOME/.cargo/bin/cargo$HOME/.cargo/bin/rustcのPATHが通っていて気持ち悪かったので調査しました。


結論

rustup使用時に~/.profileに以下の設定が入ることがわかりました。

  1. rustup install時に1を選択する

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    1) Proceed with standard installation (default - just press enter)
    2) Customize installation
    3) Cancel installation
    
  2. ~/.profileに以下が自動的に記載される。

    . "$HOME/.cargo/env"
    
  3. ~/.profileはシェルにログイン時に読み込まれる

  4. ~/.cargo/envがPATHを通している。

    #!/bin/sh
    # rustup shell setup
    # affix colons on either side of $PATH to simplify matching
    case ":${PATH}:" in
        *:"$HOME/.cargo/bin":*)
            ;;
        *)
            # Prepending path in case a system-installed rustc needs to be overridden
            export PATH="$HOME/.cargo/bin:$PATH"
            ;;
    esac
    
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?