Rust create ubuntu / debian package from cargo

Rust how to create a deb package with cargo deb

Rust create ubuntu / debian package from cargo

Distribution is king. It's amazingly easy to create a .deb package for your rust program via the cargo-deb crate.

Here's an example tutorial example:

cargo new myprogram
cd myprogram
$ cat src/main.rs 
fn main() {
    println!("Hello, world!");
}

# Of course, your program will be more that just hello world.

# Now, install cargo-deb
cargo install cargo-deb

# Create a metadescription for your program in your Cargo.toml file. e.g

$ cat Cargo.toml 
[package]
name = "myprogram"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]


[package.metadata.deb]
maintainer = "Chris <chris@example.com>"
copyright = "2021, 2021 <chris@example.com>"


# Now you can create a `deb` package for your rust program!

$ cargo deb
warning: description field is missing in Cargo.toml
warning: license field is missing in Cargo.toml
   Compiling myprogram v0.1.0 (/home/chris/Documents/programming/rust/myprogram)
    Finished release [optimized] target(s) in 0.56s
/home/chris/Documents/programming/rust/myprogram/target/debian/myprogram_0.1.0_amd64.deb

# Note you now have a `myprogram_0.1.0_amd64.deb` package in your target/debian directory. 
# Which you can distribute/install like any other .deb package. 

# Read the docs for adding things like systemd configs. https://crates.io/crates/cargo-deb

# Example installing the package

$ sudo dpkg -i /home/chris/Documents/programming/rust/myprogram/target/debian/myprogram_0.1.0_amd64.deb
[sudo] password for chris: 
Selecting previously unselected package myprogram.
(Reading database ... 354403 files and directories currently installed.)
Preparing to unpack .../myprogram_0.1.0_amd64.deb ...
Unpacking myprogram (0.1.0) ...
Setting up myprogram (0.1.0) ...

# Now your program can be ran anywhere, since the package manager will have placed your binary in your $PATH

$ myprogram 
Hello, world!





Collect recurring payments with Subscribie - Try Now