LoginSignup
4
5

More than 3 years have passed since last update.

Rustインストール奮闘記(言うほど奮闘はしていない)

Posted at

Rust とは

Rust(ラスト)はMozillaが支援するオープンソースのシステムプログラミング言語である。

特徴

  • 静的型付言語
  • 高速(C++並だとか)
  • メモリ自動管理(GCのことかと思ったがまた別物らしい)
  • 他いろいろ

下記の記事がわかりやすくておすすめです。
プログラミング言語Rustのススメ - Qiita

けっこう周りに Rust 推しが増えてきたし一度は触ってみようと思ったので、会社からいただいた勉強会の時間をつかって、ひとまず新言語入門時恒例の Hellow World 出力くらいまでやってみようと軽い気持ちではじめたものです。ただ、インストールするだけでいろいろ試行錯誤したのでひとまずここまでで一旦記事にしてみました。

ちなみに環境

  • Macbook Pro
    • macOS Sierra

余談:
「コンパイル言語なら C# でもいいけど、.NETFramework 必須だから Mac だとちょっとつらいかなー」と思って避けてたら、今は .NETCore がありましたね。こっちはまた今度やろうw

というわけでインストール

https://www.rust-lang.org/tools/install
上記公式サイトに従って行えばいいので楽ちんそうですね。
ところが Mac のOSが古いのが原因なのか接続にコケました。

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
curl: (35) SSL peer handshake failed, the server most likely requires a client certificate to connect

OpenSSL のバージョンが古いですね。これが原因の可能性は高そうです。

$ openssl version
OpenSSL 0.9.8zh 14 Jan 2016

OpenSSL のバージョンを上げます

そもそも入っていないとか言われる。

$ brew upgrade openssl
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).

(中略)

Error: openssl not installed

which コマンドで確認したところ入っているようです。わけがわからないよ。

$ which openssl
/usr/bin/openssl

インストールされてないと言われたのでインストールから実施してみました。するとさっき確認した実行パスと違うところに入りました。

$ brew install openssl

(中略)

==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2t: 1,795 files, 12.4MB

Homebrew でインストールすると別のところに入るんですね。であれば実行パスを Homebrew でインストールしたほうに変えれば万事おkそうです。

$ echo 'export PATH=/usr/local/Cellar/openssl/1.0.2t/bin:$PATH' >> ~/.bash_profile

OpenSSLのバージョンアップが確認できました。

$ which openssl
/usr/local/Cellar/openssl/1.0.2t/bin/openssl

$ openssl version
OpenSSL 1.0.2t  10 Sep 2019

インストールを再開します

進捗、ダメです( ゚д゚)

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
curl: (35) SSL peer handshake failed, the server most likely requires a client certificate to connect

curlで OpenSSL が使われていないっぽい。。。そもそもそういう話か。

$ curl --version
curl 7.54.0 (x86_64-apple-darwin16.0) libcurl/7.54.0 SecureTransport zlib/1.2.8
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets

諦めて別の方法にします

Other Installation Methods - Rust Forge

On Unix, run curl https://sh.rustup.rs -sSf | sh in your shell.

curlに OpenSSL が使われていなくて、さてどうしたものかと考えていましたが、Macならこれでも良さそうです。ちなみにWindowsはインストーラーがあるみたいです。

早速実行してみます

おお…うまくいくやん。
セキュリティの警告はひとまずスルーします。途中でインストールオプションを聞かれるので、特に理由がなければデフォルトである 1 を入力してエンターを押すとインストールが継続します。

$ curl https://sh.rustup.rs -sSf | sh
info: downloading installer
Warning: Detected OS X platform older than 10.13
Warning: Not forcing TLS v1.2, this is potentially less secure

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

It will add the cargo, rustc, rustup and other commands to
Cargo's bin directory

(略)

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1

下記メッセージが表示されればインストール完了です。

Rust is installed now. Great!

To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH
environment variable. Next time you log in this will be done
automatically.

To configure your current shell run source $HOME/.cargo/env

一応コマンドで動作確認

前項で cargo, rustc, rustup のコマンドが追加されることがメッセージ内に書かれていました。なのでこれを実行して確認してみます。

$ cargo --version
cargo 1.39.0 (1c6ec66d5 2019-09-30)

$ rustc --version
rustc 1.39.0 (4560ea788 2019-11-04)

$ rustup --version
rustup 1.20.2 (13979c968 2019-10-16)

OKそうですね!

最後に

なんだかインストールひとつにえらい手間どってしまいました。たぶん Mac の OS が少し古いせいかとは思いますが、もし私と似たような境遇で Rust のインストールに困っている方は同じようにするとうまくいくかもしれません。よかったら試してみてください。

参考

次はRustを使って何かやってみようかと思います。

4
5
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
5