cannot open output file a.out: Permission denied, on a simple compilation

37,111

Solution 1

Move to a directory where you are allowed to write.

Solution 2

This is because if you only have write permissions, but you are not the owner the directory.

  1. Check your user name:

    whoami
    
  2. Make yourself the owner of the directory and its contents:

     sudo chown -R "$USER:" /path/to/the/directory
    
  3. Set read/write/execute permission

    chmod -R 700 /path/to/the/directory
    

refer https://askubuntu.com/questions/466605/cannot-open-output-file-permission-denied

Share:
37,111
sd1517
Author by

sd1517

Updated on December 12, 2020

Comments

  • sd1517
    sd1517 over 3 years

    I wrote some code in vim and whenever I try to run the code it shows this:

    coolmego@coolmego-PC:~/coolmego/cprograms$ gcc dfs8puzz.c 
    /usr/bin/ld: cannot open output file a.out: Permission denied
    collect2: ld returned 1 exit status
    coolmego@coolmego-PC:~/coolmego/cprograms$ ./a.out
    bash: ./a.out: No such file or directory
    

    What should I do?