본문 바로가기

진리는어디에

[Rust] Rust 설치하기

설치하기

우리가 rust를 시작하기 전 가장 먼저해야 할 일은 rust를 설치하는 것이다. 본 포스트에서는 rustup이라고 하는 러스트 버전 및 관련 도구들을 관리하기 위한 커맨드 라인 툴을 이용하여 설치할 것이다. 외에도 직접 러스트 소스 코드로 부터 컴파일 하는 방법도 있으나 이 포스트에서는 다루지 않는다. 직접 러스트를 빌드하고 싶은 분은 [여기]를 참고 하도록 하자.

윈도우에서 rustup 설치하기

윈도우에서 rust를 설치하기 위해서는 러스트 공식 사이트의 install 페이지(https://www.rust-lang.org/tools/install)에서 자신의 시스템에 맞는 rustup-init.exe를 다운 받아 실행하면 된다.

위 사이트에서 rustup-init.exe 를 다운 받아 실행하면 아래와 같은 실행화면이 나온다.

Welcome to Rust!

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

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  C:\Users\Administrator\.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  C:\Users\Administrator\.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo bin directory, located at:

  C:\Users\Administrator\.cargo\bin

This path will then be added to your PATH environment variable by
modifying the HKEY_CURRENT_USER/Environment/PATH registry key.

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:

   default host triple: x86_64-pc-windows-msvc
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

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

별다른 설정 없이 1번을 선택하면 기본적으로 C:\Users\<계정> 디렉토리 밑에 러스트 관련 파일들이 설치 된다.

Linux와 macOS에서 Rustup 설치하기

만일 여러분들이 Linux 또는 macOS를 사용중이라면, 터미널에서 다음 커맨드를 입력하도록 한다.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

위 커맨드는 스크립트를 다운로드하고 rustup 설치를 시작한다. 설치 중에 여러분의 패스워드를 입력하라고할 수도 있다. 설치가 성공적으로 끝나게 된다면 아래와 같이 출력 된다.

Rust is installed now. Great!

설치 스크립트는 여러분이 다시 로그인을 해야 러스트를 여러분의 시스템 경로에 추가한다. 만일 터미널을 재시작하지 않고 바로 사용하기를 원한다면 아래 커맨드를 실행하여 수동으로 러스트를 시스템 경로에 추가하도록 한다.

$ source $HOME/.cargo/env

혹은 ~/.bash_profile 파일에 아래와 같이 추가해도 된다.

$ export PATH="$HOME/.cargo/bin:$PATH"

~/.bash_profile 파일 수정이후에도 아래 커맨드를 실행 시켜 주어야 바로 적용 된다.

$ source ~/.bash_profile

설치 확인하기

러스트가 올바르게 설치되었는지 확인하기 위해서는 커맨드창을 열과 아래 명령을 입력 해본다.

$ rustc --version
rustc 1.62.0 (a8314ef7d 2022-06-27)

정상적으로 설치 되었다면 버전 정보와 배포된 스테이블 버전의 커밋일자가 출력된다.

러스트 최신 버전 업데이트하기

만일 러스트 설치 이후 최신 버전으로 업데이트가 필요하다면 아래와 같이 업데이트 커맨드를 입력한다.

$ rustup update

러스트 제거하기

설치를 했다면 제거가 필요한 경우도 있다. 러스트를 제거하기 위해서는 아래 명령을 이용하면 관련 파일 삭제뿐 아니라 환경 변수들도 삭제 된다.

$ rustup self uninstall

마치며

이상 러스트 프로그래밍을 시작하기에 앞어 러스트 설치에 대해 알아 보았다. 다음 포스트에서는 모든 프로그래밍에 시작인 'Hello World'를 출력하는 방법을 살펴 보도록하겠다.

만일 Visual Studio Code를 러스트를 개발하는 IDE로 활용하고 싶으신 분이라면 [Rust] Visual Studio Code에서 Rust 연동 포스트도 도움이 될 것이니 한번 살펴 볼것을 권한다.

부록 1. 같이 읽으면 좋은 글

유익한 글이었다면 공감(❤) 버튼 꾹!! 추가 문의 사항은 댓글로!!