Home › C Tutorial › C installation
C installation
Full step-by-step installation for Windows, macOS and Linux.
Windows (MSYS2)
- Open
msys2.organd download the installer. - Run it, keep the default folder
C:\msys64and finish. - Open MSYS2 UCRT64 from the Start menu and run
pacman -S mingw-w64-ucrt-x86_64-gcc. Type Y to confirm. - Add
C:\msys64\ucrt64\binto your PATH: open the Start menu, search Edit the system environment variables, click Environment Variables, select Path, click Edit, then New, and pasteC:\msys64\ucrt64\bin. - Close and reopen your terminal (Command Prompt or PowerShell).
macOS
- Open the Terminal app.
- Run
xcode-select --installand click Install in the window that appears. - Wait until the download finishes.
Linux (Ubuntu or Debian)
- Open a terminal and run
sudo apt update. - Run
sudo apt install build-essential. On Fedora usesudo dnf install gcc gcc-c++.
Check the installation
- Open a new terminal.
- Run
gcc --version. A version number means it works.
Run your first program
- Create a folder and a file named
hello.c. Paste the code from the editor below. - In the terminal, go to that folder with
cd. - Compile with
gcc hello.c -o hello. - Run it with
./hello(on Windows usehello.exe).
If something goes wrong
'gcc' is not recognized: the PATH step is missing, or you did not reopen the terminal.- Errors with line numbers: read the first error, fix it and compile again.
Example code
#include <stdio.h>
int main(void) {
puts("C is installed");
return 0;
}