{"id":65260,"date":"2022-06-22T09:00:33","date_gmt":"2022-06-22T09:00:33","guid":{"rendered":"https:\/\/www.cryptocabaret.com\/?p=65260"},"modified":"2022-06-22T09:00:33","modified_gmt":"2022-06-22T09:00:33","slug":"manage-your-rust-toolchain-using-rustup","status":"publish","type":"post","link":"https:\/\/www.cryptocabaret.com\/?p=65260","title":{"rendered":"Manage your Rust toolchain using rustup"},"content":{"rendered":"<p><span class=\"field field--name-title field--type-string field--label-hidden\">Manage your Rust toolchain using rustup<\/span><br \/>\n<span class=\"field field--name-uid field--type-entity-reference field--label-hidden\"><a title=\"View user profile.\" href=\"https:\/\/opensource.com\/users\/gkamathe\" class=\"username\">Gaurav Kamathe<\/a><\/span><br \/>\n<span class=\"field field--name-created field--type-created field--label-hidden\">Wed, 06\/22\/2022 &#8211; 03:00<\/span><\/p>\n<div data-drupal-selector=\"rate-node-70078\" class=\"rate-widget-thumbs-up\" title=\"Register or Login to like.\">\n<div class=\"rate-thumbs-up-btn-up vote-pending\">2 readers like this<\/div>\n<div class=\"rate-score\">2 readers like this<\/div>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item\">\n<p>The <a href=\"https:\/\/www.rust-lang.org\/\">Rust programming language<\/a> is becoming increasingly popular these days, used and loved by hobbyists and corporations alike. One of the reasons for its popularity is the amazing tooling that Rust provides making it a joy to use for developers. <a href=\"https:\/\/github.com\/rust-lang\/rustup\">Rustup<\/a> is the official tool used to manage Rust tooling. Not only can it be used to install Rust and keep it updated, it also allows you to seamlessly switch between the stable, beta, and nightly Rust compilers and tooling. This article will introduce you to rustup and some common commands to use.<\/p>\n<h2><strong>Default Rust installation method<\/strong><\/h2>\n<p>If you want to install Rust on Linux, you can use your package manager. On Fedora or CentOS Stream you can use this, for example:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> dnf <span class=\"kw2\">install<\/span> rust cargo<\/div><\/div><\/pre>\n<p>This provides a stable version of the Rust toolchain, and works great if you are a beginner to Rust and want to try compiling and running simple programs. However, because Rust is a new programming language it changes fast and a lot of new features are frequently added. These features are part of the nightly and later beta version of the Rust toolchain. To try out these features you need to install these newer versions of the toolchain, without affecting the stable version on the system. Unfortunately, your distro\u2019s package manager can\u2019t help you here.<\/p>\n<h2>Installing Rust toolchain using rustup<\/h2>\n<p>To get around the above issues, you can download an install script:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">$ curl <span class=\"re5\">--proto<\/span> <span class=\"st_h\">'=https'<\/span> --tlsv1.2 <br><span class=\"re5\">-sSf<\/span> https:<span class=\"sy0\">\/\/<\/span>sh.rustup.rs <span class=\"sy0\">&gt;<\/span> sh.rustup.rs<\/div><\/div><\/pre>\n<p>Inspect it, and then run it. It doesn\u2019t require root privileges and installs Rust accordingly to your local user privileges:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">$ <span class=\"kw2\">file<\/span> sh.rustup.rs<br>\nsh.rustup.rs: POSIX shell script, ASCII text executable<br>\n$ <span class=\"kw2\">less<\/span> sh.rustup.rs<br>\n$ <span class=\"kw2\">bash<\/span> sh.rustup.rs<\/div><\/div><\/pre>\n<p>Select option 1 when prompted:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\"><span class=\"nu0\">1<\/span><span class=\"br0\">)<\/span> Proceed with installation <span class=\"br0\">(<\/span>default<span class=\"br0\">)<\/span><br><span class=\"nu0\">2<\/span><span class=\"br0\">)<\/span> Customize installation<br><span class=\"nu0\">3<\/span><span class=\"br0\">)<\/span> Cancel installation<br><span class=\"sy0\">&gt;<\/span> <span class=\"nu0\">1<\/span><\/div><\/div><\/pre>\n<p>After installation, you must source the environment variables to ensure that the <code>rustup<\/code> command is immediately available for you to use:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"kw3\">source<\/span> <span class=\"re1\">$HOME<\/span><span class=\"sy0\">\/<\/span>.cargo<span class=\"sy0\">\/<\/span><span class=\"kw2\">env<\/span><\/code><\/span><\/pre>\n<p>Verify that the Rust compiler (rustc) and Rust package manager (cargo) are installed:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">$ rustc <span class=\"re5\">--version<\/span><br>\n$ cargo <span class=\"re5\">--version<\/span><\/div><\/div><\/pre>\n<\/p>\n<div class=\"embedded-resource-list callout-float-right\">\n<div class=\"field field--name-title field--type-string field--label-hidden field__item\">Programming and development<\/div>\n<div class=\"field field--name-links field--type-link field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/developers.redhat.com\/?intcmp=7016000000127cYAAQ\">Red Hat Developers Blog<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/cheat-sheets?intcmp=7016000000127cYAAQ\">Programming cheat sheets<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/www.redhat.com\/en\/services\/training\/learning-subscription?intcmp=7016000000127cYAAQ\">Try for free: Red Hat Learning Subscription<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/bash-programming-guide?intcmp=7016000000127cYAAQ\">eBook: An introduction to programming with Bash<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/developers.redhat.com\/cheat-sheets\/bash-shell-cheat-sheet?intcmp=7016000000127cYAAQ\">Bash shell scripting cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/developers.redhat.com\/e-books\/modernizing-enterprise-java?intcmp=7016000000127cYAAQ\">eBook: Modernizing Enterprise Java<\/a><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<h2>See installed and active toolchains<\/h2>\n<p>You can view the different toolchains that were installed and which one is the active one using the following command:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span>rustup show<\/div><\/div><\/pre>\n<h2>Switch between toolchains<\/h2>\n<p>You can view the default toolchain and change it as required. If you\u2019re currently on a stable toolchain and wish to try out a newly introduced feature that is available in the nightly version you can easily switch to the nightly toolchain:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">$ rustup default<br>\n$ rustup default nightly<\/div><\/div><\/pre>\n<p>To see the exact path of the compiler and package manager of Rust:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">$ rustup <span class=\"kw2\">which<\/span> rustc<br>\n$ rustup <span class=\"kw2\">which<\/span> cargo<\/div><\/div><\/pre>\n<h2>Checking and Updating the toolchain<\/h2>\n<p>To check whether a new Rust toolchain is available:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span>rustup check<\/code><\/span><\/pre>\n<p>Suppose a new version of Rust is released with some interesting features, and you want to get the latest version of Rust. You can do that with the <code>update<\/code> subcommand:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span>rustup update<\/code><\/span><\/pre>\n<h2>Help and documentation<\/h2>\n<p>The above commands are more than sufficient for day-to-day use. Nonetheless, rustup has a variety of commands and you can refer to the help section for additional details:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span>rustup <span class=\"re5\">--help<\/span><\/code><\/span><\/pre>\n<p>Rustup has an entire <a href=\"https:\/\/rust-lang.github.io\/rustup\/\">book<\/a> on GitHub that you can use as a reference. All the Rust documentation is installed on your local system, which does not require you to be connected to the Internet. You can access the local documentation which includes the book, standard library, and so on:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">$ rustup doc<br>\n$ rustup doc <span class=\"re5\">--book<\/span><br>\n$ rustup doc <span class=\"re5\">--std<\/span><br>\n$ rustup doc <span class=\"re5\">--cargo<\/span><\/div><\/div><\/pre>\n<p>Rust is an exciting language under active development. If you\u2019re interested in where programming is headed, keep up with Rust!<\/p>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-field-article-subhead field--type-text-long field--label-hidden field__item\">\n<p>Rustup can be used to install Rust and keep it updated. It also allows you to seamlessly switch between the stable, beta, and nightly Rust compilers and tooling.<\/p>\n<\/div>\n<div class=\"field field--name-field-lead-image field--type-entity-reference field--label-hidden field__item\">\n<article class=\"media media--type-image media--view-mode-caption\">\n<div class=\"field field--name-field-media-image field--type-image field--label-hidden field__item\">  <img decoding=\"async\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/06\/tools_hardware_purple.png\" width=\"520\" height=\"292\" alt=\"Tools illustration\" title=\"Tools illustration\" loading=\"lazy\"><\/div>\n<div class=\"field field--name-field-caption field--type-text-long field--label-hidden caption field__item\"><span class=\"caption__byline\">Image by: <\/span><\/p>\n<p>Opensource.com<\/p>\n<\/div>\n<\/article>\n<\/div>\n<div class=\"field field--name-field-tags field--type-entity-reference field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/rust\" hreflang=\"en\">Rust<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/programming\" hreflang=\"en\">Programming<\/a><\/div>\n<\/p><\/div>\n<div class=\"field field--name-field-listicle-title field--type-string field--label-hidden field__item\">What to read next<\/div>\n<div class=\"field field--name-field-listicles field--type-entity-reference field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/article\/21\/7\/rust-tools-linux\" hreflang=\"und\">5 Rust tools worth trying on the Linux command line<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/article\/21\/3\/rust-programmer\" hreflang=\"und\">5 signs you might be a Rust programmer<\/a><\/div>\n<\/p><\/div>\n<div class=\"field field--name-field-default-license field--type-list-string field--label-hidden field__item\"><a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\"><br \/>\n        <img decoding=\"async\" alt=\"Creative Commons License\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/06\/cc-by-sa--28.png\" title=\"This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.\"><\/a>This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.<\/div>\n<section class=\"field field--name-field-comments field--type-comment field--label-hidden comment-wrapper\">\n<div class=\"comments__count\">\n<div class=\"login\"><a href=\"https:\/\/opensource.com\/user\/register?absolute=1\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml&amp;absolute=1\">Login<\/a> to post a comment.<\/div>\n<\/p><\/div>\n<\/section>\n<p class=\"wpematico_credit\"><small>Powered by <a href=\"http:\/\/www.wpematico.com\" target=\"_blank\" rel=\"noopener\">WPeMatico<\/a><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Manage your Rust toolchain using rustup Gaurav Kamathe Wed, 06\/22\/2022 &#8211; 03:00 2 readers like this 2 readers like this The Rust programming language is becoming increasingly popular these days, used and loved by hobbyists and corporations alike. One of the reasons for its popularity is the amazing tooling that Rust provides making it a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":65261,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[307],"tags":[],"class_list":["post-65260","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-open-source"],"_links":{"self":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/65260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=65260"}],"version-history":[{"count":0,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/65260\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/media\/65261"}],"wp:attachment":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=65260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=65260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}