Where to Find Information About Rust
To install Rust, check out the instructions at
https://www.rust-lang.org/learn/get-started
Currently you can install Rust on the Mac using
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
and on Windows using the installer found at here or check the page on “Other installation methods” linked to from the getting started page.
Installing on Mac
I found the installation on the Mac nearly completely painless. All I had to do was paste the command into a terminal and hit the return key a few times. Then, I had to add the directory cargo/bin, which the installation had created in my home directory, to the PATH environment variable. This can be done by doing source .profile
since the installer created a .profile file.
For some reason .profile wasn’t loading automatically when I started a shell, so I added that to .zshrc, since I’m using z-shell.
Installing on Windows
On Windows the installation only involved running the installer, and I didn’t have to manually fix the PATH.
Creating a Rust Program
I plan to use Visual Studio Code for my editor (it’s free) so I installed that, set the working folder to a new folder, then clicked the extensions button and installed the first extension that came up when I searched for “Rust”.
Following this, I decided to read The Rust Programming Language. But don’t worry; whatever I learn there or elsewhere I’m going to document in the following posts.
This online book suggests writing a “hello world” program, so I created a file called main.rs and typed this code into it
Note, there is an exclamation mark after println
and that line ends in a semi-colon.
When I restarted VSCode on the Mac it insisted I update the extension I’d just installed, so I did that too.
To run it, although the extension I’d installed seemed to do syntax highlighting just fine, I couldn’t spot a run button, so I opened a terminal from the terminal menu in VS Code and typed rustc main.rs
.
Finally I was able to run rustc, and it created a file called main, which I ran using ./main
in the terminal. Success!
Hi john! I just did that myself! Do you have plans to develop a project in Rust? Exciting stuff.