Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied (os error 13) when cargo build #6757

Closed
lowesyang opened this issue Mar 16, 2019 · 40 comments
Closed

Permission denied (os error 13) when cargo build #6757

lowesyang opened this issue Mar 16, 2019 · 40 comments
Labels
C-bug Category: bug

Comments

@lowesyang
Copy link

lowesyang commented Mar 16, 2019

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 (f099fe9 2019-02-12)

@lowesyang lowesyang added the C-bug Category: bug label Mar 16, 2019
@ehuss
Copy link
Contributor

ehuss commented Mar 22, 2019

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).

@collin5
Copy link
Contributor

collin5 commented Mar 29, 2019

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

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

@ehuss
Copy link
Contributor

ehuss commented Apr 4, 2019

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

@ehuss ehuss closed this as completed Apr 4, 2019
@jeromegn
Copy link

jeromegn commented Apr 10, 2019

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.

bors added a commit that referenced this issue Apr 12, 2019
Better error if PathSource::walk can't access something.

Reported at #6757 (comment).
@chanks
Copy link

chanks commented Sep 14, 2019

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.

@joseluisq
Copy link

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!

@zwobill
Copy link

zwobill commented Dec 25, 2019

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.

@ivnsch
Copy link

ivnsch commented Jun 13, 2020

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.

@jamesmcl113
Copy link

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

@Groumph
Copy link

Groumph commented Jul 19, 2020

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.

@dchen327
Copy link

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.

@Peter-L-SVK
Copy link

Peter-L-SVK commented Dec 3, 2020

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

@rsweeneydev
Copy link

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.

@JakePi3
Copy link

JakePi3 commented Dec 27, 2020

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.

@Kambaa
Copy link

Kambaa commented Dec 31, 2020

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.

[UPDATE]: After installing the mentioned apps, closing and re-openning the WSL command line seems to do the trick.

@juhams
Copy link

juhams commented Apr 11, 2021

close vscode , carcgo clean , cargo run

@shiranningning
Copy link

close vscode , carcgo clean , cargo run

it works,but why? How does vscode affect this?

@M0hammedImran
Copy link

M0hammedImran commented Apr 25, 2021

In some weird way closing vscode and running cargo works as expected. But when vscode is open in a remote session I get console error: caused by: Permission denied (os error 13)
I'm running console rustc 1.51.0 (2fd73fabe 2021-03-23) on Ubuntu 20.04 ie. WSL1

@Taptiive
Copy link

These are the steps i followed to solve this on WSL 2 with Arch:

  1. Close VS Code
  2. Reopen WSL Terminal
  3. If your project folder is inside your Windows files try moving it into the linux home directory
  4. cargo clean
  5. cargo run

I hope this is useful for someone.

@joeftiger
Copy link

joeftiger commented May 1, 2021

I have the same issue under Arch Linux.

I installed rustup with the distro's package manager pacman. I never had problems until very recently.
cargo-config installed fine, but xargo fails with os error 13. I chowned everything in my home directory, reinstalled rustup but still no luck usin cargo install xargo.

EDIT: I just setup rustup for root and tried cargo install xargo there: Still os error 13. This is very strange.

@hobbytp
Copy link

hobbytp commented Dec 27, 2021

I fixed it by following steps:

sudo apt install build-essential
and then #6757 (comment)

@itsezc
Copy link

itsezc commented Dec 28, 2021

Tried all of the approaches above :

  • Chown
  • Installing build-essential, cmake, clang
  • Closing VSCode
  • Running cargo clean and cargo run

on WSL 2 with Ubuntu, no luck. Cannot run cargo as sudo as I've used rustup to install cargo.

@gponce-ars
Copy link

This error is also triggered when running things inside Google Drive folder. Is this related to the the type of filesystem sort of thing or just a bad practice of having Git folder inside Google Drive folder?

This is happening on Mac OS version:

$uname -a 
Darwin iMac.local 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64 x86_64
$rustc --version
rustc 1.57.0 (f1edd0429 2021-11-29)

When I tested in my local folder /Users/my_user/ everything works fine.

@fahadalisarwar1
Copy link

I has to do following steps

  1. remove existing rust installation
  2. close wsl
  3. open it again
  4. sudo apt-get install build-essential cmake clang
  5. install rust for wsl
  6. close wsl again
  7. open it again and it should work
    I am using an AMD based machine

@appetrosyan
Copy link

Can reproduce on Arch. chown --R in the CARGO_HOME, RUSTUP_HOME and the project directory did nothing. What did help was mounting the target dir as tmpfs. The first thing that fails to execute is a build script.

sudo mount -t tmpfs none ./target

To me, this issue would have been much easier to fix, if the default output included the file which caused the issue. cargo spits out a butt load of information in other error cases (e.g. running out of space in the ramdisk, or running out of RAM in general) so please include the offending file in the output (and that is a cargo issue).

@jackwener
Copy link

macOS fixed by this answer

@dzmitry-lahoda
Copy link
Contributor

i am trying to build vendor in nix and getsame error. knowing where permission denied would help a lot. thank you.

@zhenzhenChange
Copy link

I also encountered this problem on the WLS2 subsystem of Windows and needed to use the sudo to install it in order to resolve it.

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

@cplir-c
Copy link

cplir-c commented May 31, 2023

I had this issue yesterday, and running with sudo with the clang and gcc toolchains installed didn't help.
ls -l confirmed the file was executable, and I tried chmod +x anyway, but it didn't help.

I ended up telling cargo to build targets in /tmp/cargo-target:

~/.cargo/config:

[build]
target-dir = "/tmp/cargo-target"

I did this so it would be on the tmpfs filesystem instead of my git f2fs one.
I wouldn't be surprised if this broke the inter-project build cache (by making them share a folder). Is there a way to make it named after the build directory but still in /tmp?

@themighty1
Copy link

fwiw, running strace cargo build will show you the offending path which triggered this error.

@Valerka2307
Copy link

I had the same problem. When I reinstalled my os, I downloaded my directories to the cloud. After reinstalling returned my data to home and found this problem. I solved this by recoping code to similar directory which created from scratch.

@huongnguyenduc
Copy link

Just run sudo rm -rf ./target/debug and cargo build, and it will work again.

@appetrosyan
Copy link

@huongnguyenduc Aside from this being recommended more than 5 times in just this thread, it doesn’t work for everyone.

@amesy
Copy link

amesy commented Feb 20, 2024

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

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

thank you, this very useful.

@Sberm
Copy link

Sberm commented Mar 24, 2024

For me it's not having permission to write to target dir, then the solution becomes

sudo chown -R $(whoami) <project-dir>

@TAOFOR4
Copy link

TAOFOR4 commented May 6, 2024

Hi, my issue is

error: failed to read `/Cargo.toml`

Caused by:
  Permission denied (os error 13)

I've tried all the methods here but doesn't work. I am in Ubuntu 22 not WSL but a real OS.

@cplir-c
Copy link

cplir-c commented May 7, 2024

Hi, my issue is

error: failed to read `/Cargo.toml`

Caused by:
  Permission denied (os error 13)

I've tried all the methods here but doesn't work. I am in Ubuntu 22 not WSL but a real OS.

On unix-like systems like Ubuntu, / is the root of the file system, kind of like the default C:\\ on Windows. Your path there is in that filesystem root directory. Maybe you meant ./Cargo.toml or just Cargo.toml to refer to one in your current directory?

@mustzev
Copy link

mustzev commented Sep 1, 2024

In my case, I was using a Linux system but my project folder was on a mounted hard drive with FAT file system. I formatted the hard drive with Ext4 file system (the same as my Linux system drive), copied over my project folder again, and everything worked okay.

@cybergazer
Copy link

Closed issue, 50+ upvotes, 0 fix. This issue makes tauri unusable

@kurushimee
Copy link

Had this issue on Ubuntu WSL2 under Windows 11. Fixed it by installing gcc and clang which were missing, not sure which of the two was actually required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests