How do I install packages with Rust?

I’m trying to create a Rust app in Glitch, and I’m having trouble installing new packages through cargo.

I’ve found at least two projects that are using Rust already:

  • hello-rust is using Iron as a backend, which it’s pulling into Cargo.toml. In a thread about language support from last year, the author mentions installing other Rust packages, like actix.
  • rust-web-server is using vanilla Rust, no third-party packages

The first example showed that installing packages worked at some point!

But if I remix either of these projects and start trying to installing my own dependencies (or in the cast of hello-rust, just run it in my own namespace), I get an error from Cargo:

$ cargo build
error: failed to load source for a dependency on `oauth-client`

Caused by:
  Unable to update registry ``

Caused by:
  failed to open: /opt/rust/cargo/registry/index/

Caused by:
  Permission denied (os error 13)

Inspecting it in the console, I see that the directory is owned by root:

$ ls -l /opt/rust/cargo
total 8
drwxr-xr-x 2 root root 4096 Jun 28 03:39 bin
-rw-r--r-- 1 root root   40 Jun 28 03:40 env

Am I missing something I should be doing to install packages with Rust? Have the permissions on this directory changed in the last year or something?

(This might also just be a bad idea, if Glitch has to recompile dependencies on cold start. Just curious if I’m missing something, because I couldn’t find explanations for this error elsewhere!)

os error 13 translates to this: you cant edit those files, nor can the system.

oh! welcome to the glitch support community!

Hi, I wrote the hello-rust template, and can confirm it did work at some point, but no longer does now that I check it.

At a guess, it would seem Glitch no longer allows access to the location cargo was using to store files, or else Glitch’s version of cargo has been updated and has breaking changes to the way it stores files that aren’t compatible with Glitch.

It’s difficult to say where the issue lies, without insight from the Glitch team.


@Glitch_Support is this something that users can fix/work on?

I’ve passed this onto the team to see if it’s a regression that can be fixed!


Thanks! Let me know if this is something the community can help with.


no one’s asking for a workaround, but here’s one anyway: install a whole separate copy of rust in a location where we do have permissions.

export RUSTUP_HOME=/tmp/rustup
export CARGO_HOME=/tmp/cargo
export CARGO_TARGET_DIR=/tmp/target
curl --proto '=https' --tlsv1.2 -sSf | sh -s -- -y

bad idea, if Glitch has to recompile dependencies on cold start

but it would have to do that for Node.js too, so maybe that’s not too bad

1 Like

that is exactly what the global workaround does! ( for nodejs anyway )

Good to know I’m not missing anything obvious!

Thanks for all the suggestions – I ended up writing my first Glitch app in Python instead of Rust, and I’ll probably stick to that better-trodden path until something changes.