Running compiled program in Ubuntu

Posted on 2011-04-30
Last Modified: 2012-05-11
Hey Experts,

I have a problem with my Ubuntu install. When I compile a program I get some runnable code that is in a file called a.out. I can't simply type


in the terminal because it won't run. I need to type


and it will run fine. How do I make it so I don't have to type a dot and a slash before running code?

Question by:jeffiepoo
    LVL 9

    Expert Comment

    Set your PATH variable in the environment to include the directory where the file is being created.

    LVL 68

    Accepted Solution

    That's because the current directory (the dot "." is a hard link to the current directory) is not in your PATH.


    ... either add the dot to your PATH (which is not really recommended for security reasons):

    export PATH=$PATH:.

    Add the above to your $HOME/.profile shell initialization file at the end.

    ... or put your executables in a common place like /usr/local/bin (create this directory if needed) and add it to your PATH:

    export PATH=$PATH:/usr/local/bin

    Again, add this to your $HOME/.profile shell initialization file at the end.

    Now logout/login again to make the new setting active, or issue the desired statement from above from the commandline for a temporary change lasting until the next logout/login.


    LVL 2

    Expert Comment

    Or you can type this in the terminal: "gcc program.c; ./a.out" (if you don't use gcc, you'll have to modify it)
    It compiles and runs the program automatically.
    LVL 61

    Expert Comment

    excluding current directory from executables path is a security measure.
    LVL 6

    Author Comment

    Whoever marked this as abandoned is dumb. It isn't even 3 weeks old. I just haven't gotten to trying out the suggestions. Thx
    LVL 61

    Expert Comment


    normally yo make a makefile which would call

    $CC x.c -o bin/x

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
    Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
    In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
    Video by: Phil
    This video goes over how to configure and start a jail in FreeBSD.  This video is meant to supplement the article included with this course.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now