1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

macbookでRustの環境構築した際のエラー(os error 17, os error 13)

Last updated at Posted at 2024-07-21

はじめに

MacBookを買って、なにか新しいことを始めたいと思い、最近ホットなRust言語に手を出してみました。
まあ、Reactの勉強中ということもあって、本格的には始めませんが、環境構築だけでもやっとくか。と思い、いろいろ試してみるとあまり情報がないエラーが出てきてしまったので、その対処をまとめます。

記事を参考に環境構築

環境構築に参考にした記事は以下です。

発生した問題

非常に参考になったんですが、rustup-initを実行してセットアップしようとしたところ、以下のようなエラーが発生しました。

error: could not create link from '/Users/hoge/.cargo/bin/rustup' to '/Users/hoge/.cargo/bin/rustfmt': File exists (os error 17)

このエラーはrustup-initコマンドを実行してRustをインストールしようとしたときに、既存のファイルやシンボリックリンクが原因で新しいリンクを作成できなかったことを示しているそうですが、私は一度もRustを触ったことがないので、なぜこのようなエラーが出たのか不明です。
このエラーの対処法として、以下のコマンドを実行しました。

rm /Users/hoge/.cargo/bin/rustfmt
rm -rf ~/.rustup ~/.cargo

その後再度、rustup-initコマンドを実行しました。

ところが、次は以下のようなエラーが発生しました。

error: could not amend shell profile: '/Users/hoge/.bash_profile': could not write rcfile file: '/Users/hoge/.bash_profile': Permission denied (os error 13)

17番エラーから13番エラーに変わったけど、なにがなんやら…
調べてみると権限の問題で書き込みが出来ないというエラーらしく、書き込みの権限を与えるために所有権を変更する必要があるとのこと。
以下のコマンドを実行して、所有者と権限を確認し、書き込み権限がない場合は権限を与えます。

ls -l ~/.bash_profile
sudo chown $(whoami) ~/.bash_profile
chmod u+w ~/.bash_profile

.bash_profileがない場合は、以下のコマンドでファイルを作成し、権限を付与します。

touch ~/.bash_profile
chmod 644 ~/.bash_profile

その後再度、rustup-initコマンドを実行したところ、問題なくセットアップすることができました。

あとは、参考記事のとおり、ターミナルを再起動し、

cargo --version
rustc --version
rustdoc --version
rustup --version

のコマンドでそれぞれバージョンの確認が取ることができれば完了です。

まとめ

今回なぜこのような問題が発生したか不明ですが、おそらくインストールしていたパスが良くなかったのかな~と思ってます。
同じような問題で困っている方がいれば参考にしていただければと思います。
とりあえず、環境構築だけ済ませてReactの勉強に戻ります。
それでは!!!

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?