Cargo: Permission denied (os error 13) when cargo build

Created on 16 Mar 2019  路  15Comments  路  Source: rust-lang/cargo

Problem
After i install rust and cargo using curl https://sh.rustup.rs -sSf | sh, and try to build a new project, An error threw:

image

And if i use sudo cargo build, it fix.
But at some situation i have to use just cargo build, how can i solve the problem?

Notes
OS: mac OS Mojave 10.14.3
Output of cargo version: cargo 1.33.0 (f099fe94b 2019-02-12)

C-bug

Most helpful comment

I am running into this issue with VSCode Remote Try Rust. Cargo prints error: Permission denied (os error 13) I've tried way mentioned above. chown, cargo clean, didn't help. Now I don't know where it gets access denied. I think we could improve the error message by including a little bit more context.

All 15 comments

It sounds like there are some permission issues in your home directory. You may have better luck asking on one of the forums (like https://users.rust-lang.org/) or maybe one of the chat platforms (like Discord).

@yyh1102 Have you tried changing permissions of your cargo home dir. i.e

$ sudo chown -R $(whoami) /Users/lowesyang/.cargo/

I'm going to close this, this does not seem to be a cargo issue.

I've started getting the same recently, I ran it with RUST_LOG=debug and got:

$ RUST_LOG=debug RUST_BACKTRACE=1 cargo build --bin runner
...
[2019-04-10T20:17:35Z DEBUG globset] built glob set; 0 literals, 2 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 1 regexes
[2019-04-10T20:17:35Z INFO  cargo::util::rustc] updated rustc info cache
[2019-04-10T20:17:35Z DEBUG cargo] exit_with_error; err=CliError { error: Some(Os { code: 13, kind: PermissionDenied, message: "Permission denied" }

stack backtrace:
   0: failure::backtrace::internal::InternalBacktrace::new::h8d6d9abeadb47698 (0x560037bbe9f3)
   1: failure::backtrace::Backtrace::new::hc66590c50d3d5a2a (0x560037bbe69f)
   2: cargo::sources::path::PathSource::walk::h156df4e3b728b6cd (0x5600376ea601)
   3: cargo::sources::path::PathSource::walk::h156df4e3b728b6cd (0x5600376ea955)
   4: cargo::sources::path::PathSource::list_files::h7bdb580f82226180 (0x5600376e761e)
   5: cargo::sources::path::PathSource::last_modified_file::h327eac454607eb9c (0x5600376eabcd)
   6: <cargo::sources::path::PathSource<'cfg> as cargo::core::source::Source>::fingerprint::he55956dc9cd9bc4c (0x5600376eb815)
   7: cargo::core::compiler::fingerprint::pkg_fingerprint::hc05670626ba10a80 (0x56003775cc9c)
   8: cargo::core::compiler::fingerprint::prepare_build_cmd::hb5f29c2698ba1b07 (0x560037759366)
   9: cargo::core::compiler::custom_build::prepare::h28cf21ba620f65f9 (0x560037511e7b)
  10: cargo::core::compiler::compile::h87829c6f40288c15 (0x56003775ef06)
  11: cargo::core::compiler::compile::h87829c6f40288c15 (0x56003775f4ab)
  12: cargo::core::compiler::compile::h87829c6f40288c15 (0x56003775f4ab)
  13: cargo::core::compiler::context::Context::compile::hc59394fe8834cb3d (0x5600376d2ce4)
  14: cargo::ops::cargo_compile::compile_ws::hcd03deb2dd8e37c3 (0x5600374a5af0)
  15: cargo::ops::cargo_compile::compile::h57d9550ec550a472 (0x5600374a1db8)
  16: cargo::commands::build::exec::hc595c6a2b98b3047 (0x56003742b17d)
  17: cargo::cli::main::hbbce86d40638f2f0 (0x5600373f0c55)
  18: cargo::main::ha6397e0193ae2834 (0x56003740ee1f)
  19: std::rt::lang_start::{{closure}}::h783b28c4e06ed518 (0x560037404ca2)
  20: {{closure}} (0x560037be5812)
             at src/libstd/rt.rs:49
      do_call<closure,i32>
             at src/libstd/panicking.rs:297
  21: __rust_maybe_catch_panic (0x560037bf18f9)
             at src/libpanic_unwind/lib.rs:87
  22: try<i32,closure> (0x560037be63dc)
             at src/libstd/panicking.rs:276
      catch_unwind<closure,i32>
             at src/libstd/panic.rs:388
      lang_start_internal
             at src/libstd/rt.rs:48
  23: main (0x560037411441)
  24: __libc_start_main (0x7f6db17d8222)
  25: <unknown> (0x5600373e6028)), unknown: false, exit_code: 101 }
error: Permission denied (os error 13)

I've added anything that's chowned by root or any other user to the exclude package field in my Cargo.toml.

My ~/.cargo is all recursively chowned by me.

Not sure how to fix this now. The backtrace is a bit obscur.

This is using the rust 1.34 pre-release, but also on 1.33.

Edit: If I remove a folder chowned by root, this works fine. Even though the folder is in my exclude list.

I've run into this a couple of times. The chown method above didn't help, but cargo clean followed by a cargo build has fixed it. Next time I'll try building with sudo.

I've run into this a couple of times. The chown method above didn't help, but cargo clean followed by a cargo build has fixed it. Next time I'll try building with sudo.

@chanks answer worked for me. Thanks!

I am running into this issue with VSCode Remote Try Rust. Cargo prints error: Permission denied (os error 13) I've tried way mentioned above. chown, cargo clean, didn't help. Now I don't know where it gets access denied. I think we could improve the error message by including a little bit more context.

To me also nothing did work. I ran chown -R on my home directory, cargo clear, etc. So I've no idea what to do. Prepending RUST_LOG=debug RUST_BACKTRACE=1 to cargo build also isn't showing additional output.

I was using VSCode aswell, running sudo cargo clean fixed it, now cargo build (no sudo) works fine.

I just installed rustup and cargo through
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

The system in Ubuntu 20.04 in WSL 2.0.

Executing "cargo build" results in:

Compiling HelloWorld v0.1.0 (/mnt/d/Development/Rust/HelloWorld/HelloWorld)
warning: crate HelloWorld should have a snake case name
|
= note: #[warn(non_snake_case)] on by default
= help: convert the identifier to snake case: hello_world

error: could not exec the linker cc
|
= note: Permission denied (os error 13)
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/mnt/d/Development/Rust/HelloWorld/HelloWorld/target/debug/deps/HelloWorld-d682f606e8563e0e.1el6wjpgj1dkfwf0.rcgu.o" "/mnt/d/Development/Rust/HelloWorld/HelloWorld/target/debug/deps/HelloWorld-d682f606e8563e0e.3962bg4u1ufd0i2o.rcgu.o" "/mnt/d/Development/Rust/HelloWorld/HelloWorld/target/debug/deps/HelloWorld-d682f606e8563e0e.3nay2hs8vzowo41p.rcgu.o" "/mnt/d/Development/Rust/HelloWorld/HelloWorld/target/debug/deps/HelloWorld-d682f606e8563e0e.3y5j67vbwdt6naio.rcgu.o" "/mnt/d/Development/Rust/HelloWorld/HelloWorld/target/debug/deps/HelloWorld-d682f606e8563e0e.523znc2qtgcslg12.rcgu.o" "/mnt/d/Development/Rust/HelloWorld/HelloWorld/target/debug/deps/HelloWorld-d682f606e8563e0e.s16bxban93wagks.rcgu.o" "-o" "/mnt/d/Development/Rust/HelloWorld/HelloWorld/target/debug/deps/HelloWorld-d682f606e8563e0e" "/mnt/d/Development/Rust/HelloWorld/HelloWorld/target/debug/deps/HelloWorld-d682f606e8563e0e.454le8qbyd52a29h.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/mnt/d/Development/Rust/HelloWorld/HelloWorld/target/debug/deps" "-L" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-c147cd9c030850ef.rlib" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-7e62a3a07bb85bc1.rlib" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-000f77165d4d2d36.rlib" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-7dc0cb59ed386ac6.rlib" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-9248bfbd7273ac3d.rlib" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-b75363fb938de39d.rlib" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-7bbe96f555da4ad6.rlib" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-a145493c64eeb044.rlib" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-9577436fc6fce6bc.rlib" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-b3376c0a2b35415c.rlib" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-5708f6b2b59b6e0f.rlib" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-e9fd09201d99d6f4.rlib" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-914c6ef6f5cf354a.rlib" "-Wl,--end-group" "/home/nick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-1445b6c7903692a2.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-ldl" "-lutil"

error: aborting due to previous error; 1 warning emitted

error: could not compile HelloWorld.

To learn more, run the command again with --verbose.

I'm having a similar issue: when using the rustup install command from the rust homepage curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh, I get these errors:

error: could not amend shell profile: '/home/dchen327/.bash_profile'
error: caused by: could not write rcfile file: '/home/dchen327/.bash_profile'
error: caused by: Permission denied (os error 13)

I'm running Pop! OS 20.04.

Running Fedora 32 after time, I've decided to come back after some time to play with Rust:

error: command failed: 'rustc'
error: caused by: Permission denied (os error 13)

EDIT: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh helped

I was able to fix this this issue on WSL 2.0 by running.

sudo apt install build-essential

The Linux Rust installer doesn't check for a compiler toolchain, but seems to assume that you've already got a C linker installed.

Hopefully this helps someone else in the future.

Also on WSL 2.0, the os error 13 doesn't seem to differentiate between being unable to write to a file, failing to execute due to permissions or a missing executable.

To fix my problems, build-essential wasn't enough, I also had to install clang and cmake through apt, though that probably doesn't affect everyone.

I'm having this problem on my WSL, installing build-essential, clang and cmake did not worked for me. Tried with sudo, that did not work too. Please advise.

Was this page helpful?
0 / 5 - 0 ratings