8

I have installed GCC compiler by installing the build-essential package.

After the installation I wrote a simple C program. I tried to run it with the following command:

gcc First.c
./a.out

but I'm getting a bash: ./a.out: Permission denied message. I don't know what to do now.

Zanna
  • 69,223
  • 56
  • 216
  • 327
Silambarasan
  • 7,795
  • 8
  • 25
  • 26
  • 3
    Possible duplicate of [Can't execute .out files, getting permission denied](https://askubuntu.com/questions/44675/cant-execute-out-files-getting-permission-denied) (The `chmod` commands suggested in the answers here are extremely unlikely to help, for reasons described there.) – Eliah Kagan Jul 29 '19 at 11:18

3 Answers3

5

give that program (I mean a.out) the permission to "be executed" by this command:

chmod +x ./a.out

then execute it ;-)

sazary
  • 969
  • 8
  • 19
1

Execute the command

ls -l a.out

This will show the permissions granted to the file like below.

-rw-r--r-- 1 js js 0 2011-03-27 19:45 a.out

The first set is permissions and to execute it as such you need permission 'execute' Grant the execute permission using chmod +x a.out or chmod 755 a.out

Jamess
  • 3,123
  • 3
  • 27
  • 40
1

Looks like the executable file a.out doesn't have the execute (+x) mode set.

Run the command chmod a+x a.out to give the user the right to run the file. After that you can execute the file by running ./a.out in a terminal.

There's another way to achieve the same thing:

1) Right-click the a.out file in the file browser.

2) Select Properties from the drop-down menu

3) Open up the Permissions tab

4) Check the box Allow to execute this file as a program.

Bilal Akhtar
  • 2,938
  • 1
  • 18
  • 15