distrib > Mageia > 6 > x86_64 > by-pkgid > 3dd7afb0e73ef085f903dd0db1dc8c8f > files > 19


<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="generator" content="rustdoc">
    <title>Cargo, Rust’s Package Manager</title>

    <link rel="stylesheet" type="text/css" href="stylesheets/normalize.css">
<link rel="stylesheet" type="text/css" href="stylesheets/all.css">
<link rel="stylesheet" type="text/css" href="stylesheets/prism.css">

    <script src=""></script>
<link rel="icon" type="image/x-icon" href="favicon.ico">

<body class="rustdoc">
    <!--[if lte IE 8]>
    <div class="warning">
        This old browser is unsupported and will most likely display funky

    <a href='' class='fork-me'>
  <img src='images/forkme.png'/>

<div id="header">
    <a href='' class='logo'>
        <img id="logo" height=100 width=100 src='images/Cargo-Logo-Small.png'/>
    <a href="index.html">

    <div class="search">
        <form action=""
            <input name="q" class="search" placeholder="Search crates" type="text"/>

    <div class="nav">
        <a href=''>Browse All Crates</a>

        <span class='sep'>|</span>

        <div class="dropdown-container">
            <button class="dropdown">
                <span class="arrow"></span>
            <!-- Sync this list with
                 and with in this repository -->
            <ul id="current-user-links" class="dropdown" data-bindattr-503="503">
                <li><a href='index.html'>Getting Started</a></li>
                <li><a href='guide.html'>Guide</a></li>
                <li><a href='specifying-dependencies.html'>Specifying Dependencies</a></li>
                <li><a href='crates-io.html'>Publishing on</a></li>
                <li><a href='faq.html'>FAQ</a></li>
                <li><a href='manifest.html'>Cargo.toml Format</a></li>
                <li><a href='build-script.html'>Build Scripts</a></li>
                <li><a href='config.html'>Configuration</a></li>
                <li><a href='pkgid-spec.html'>Package ID specs</a></li>
                <li><a href='environment-variables.html'>Environment Variables</a></li>
                <li><a href='source-replacement.html'>Source Replacement</a></li>
                <li><a href='external-tools.html'>External Tools</a></li>
                <li><a href='policies.html'>Policies</a></li>


    <h1 class="title">Cargo, Rust’s Package Manager</h1>
<h1 id='installing' class='section-header'><a href='#installing'>Installing</a></h1>
<p>The easiest way to get Cargo is to get the current stable release of Rust by
using the <code>rustup</code> script:</p>

<pre><code class="language-shell">$ curl -sSf | sh

<p>This will get you the current stable release of Rust for your platform along
with the latest Cargo.</p>

<p>If you are on Windows, you can directly download the latest 32bit (<a href="">Rust</a>
and <a href="">Cargo</a>) or 64bit (<a href="">Rust</a> and <a href="">Cargo</a>) Rust stable releases or Cargo nightlies.</p>

<p>Alternatively, you can build Cargo from source.</p>

<h1 id='lets-get-started' class='section-header'><a href='#lets-get-started'>Let’s get started</a></h1>
<p>To start a new project with Cargo, use <code>cargo new</code>:</p>

<pre><code class="language-shell">$ cargo new hello_world --bin

<p>We’re passing <code>--bin</code> because we’re making a binary program: if we
were making a library, we’d leave it off.</p>

<p>Let’s check out what Cargo has generated for us:</p>

<pre><code class="language-shell">$ cd hello_world
$ tree .
├── Cargo.toml
└── src

1 directory, 2 files

<p>This is all we need to get started. First, let’s check out <code>Cargo.toml</code>:</p>

<pre><code class="language-toml">[package]
name = &quot;hello_world&quot;
version = &quot;0.1.0&quot;
authors = [&quot;Your Name &lt;;&quot;]

<p>This is called a <strong>manifest</strong>, and it contains all of the metadata that Cargo
needs to compile your project.</p>

<p>Here’s what’s in <code>src/</code>:</p>

<pre class="rust rust-example-rendered">
<span class="kw">fn</span> <span class="ident">main</span>() {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;Hello, world!&quot;</span>);

<p>Cargo generated a “hello world” for us. Let’s compile it:</p>

<pre><code class="language-shell">$ cargo build
<span style="font-weight: bold"
class="s1">   Compiling</span> hello_world v0.1.0 (file:///path/to/project/hello_world)</code></pre>

<p>And then run it:</p>

<pre><code class="language-shell">$ ./target/debug/hello_world
Hello, world!

<p>We can also use <code>cargo run</code> to compile and then run it, all in one step:</p>

<pre><code class="language-shell">$ cargo run
<span style="font-weight: bold"
class="s1">     Fresh</span> hello_world v0.1.0 (file:///path/to/project/hello_world)
<span style="font-weight: bold"
class="s1">   Running</span> `target/hello_world`
Hello, world!</code></pre>

<h1 id='going-further' class='section-header'><a href='#going-further'>Going further</a></h1>
<p>For more details on using Cargo, check out the <a href="guide.html">Cargo Guide</a></p>

<a href='index.html'>Install</a>
<span class='sep'>|</span>
<a href='index.html'>Getting Started</a>
<span class='sep'>|</span>
<a href='guide.html'>Guide</a>

<script type='text/javascript' src='javascripts/prism.js'></script>
<script type='text/javascript' src='javascripts/all.js'></script>