Let’s take a look at how to get started with learning C. C, unlike JavaScript, is a low-level language that needs to be compiled in advance, prior to execution. You need to download a compiler to get started, if you would like to work with C on your machine. To do this, you need to know which platform you will be working on.
Use the Hello World in C tutorial from Career Karma to test your install to see if your setup runs correctly.
MacOS
Two Options: Command Line Tools or Full XCode Install
Command Line Tools
- Open Terminal
- Run
xcode-select --install
- This prevents a full xcode install — which is not needed for simple C applications.
- Install developer command line tools when prompted.
Full XCode Install
- Open AppStore and Install XCode
- Open Terminal
- After install is complete, run
gcc
- Install developer command line tools when prompted.
Windows
Two Options: Windows Subsystem for Linux or Cygwin
Windows Subsystem for Linux (WSL)
Note: Only available for Windows 10 and higher
The Windows Subsystem for Linux is basically a minified Linux that can run in your Windows environment without the need for a traditional virtual machine.
- Go to the Microsoft Store and install WSL – Ubuntu is a solid choice when it comes to distributions, but you can choose whichever you’d like.
- Check your Windows build number. The latest version of Ubuntu requires >=Windows 10 build 16237.
- To check Windows build number, hit
Win Key + R
, type winver and enter. A window should pop up with the information (the build number will be in parentheses next to version number). You can also use the search Cortana feature and typewinver
. Click the first search item that comes up where it prompts to run the command. - If pre-16237, you’ll need to turn on developer mode by going to: Settings > Update & Security > For Developers and select “Developer mode”.
- To check Windows build number, hit
- Run bash from the command prompt or start menu.
- Run
sudo apt install build-essential
to install GCC. If you get an error, trysudo apt-get update && sudo apt-get install build-essential
- To get to your Windows drive from Bash, type:
cd /mnt/c/Users/<YourUserName>
- Note: There is no supported way to access your WSL drive from Windows command prompt.
- Run VS Code as normal.
- Note: To get VSCode’s integrated terminal to use WSL bash, add the following to your VS Code user settings:
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe"
Cygwin
Note: Prior to Windows 10. Any programs you compile with Cygwin will only run within Cygwin.
- Install Cygwin
- Launch Windows command prompt
- Install the necessary packages by running the Cygwin Setup utility.
setup-x86_64.exe -q -P wget -P gcc-g++ -P make -P diffutils -P libmpfr-devel -P libgmp-devel -P libmpc-devel
- Launch Cygwin-Terminal from its icon
To get VSCode’s integrated terminal to use Cygwin bash, add the following to your VS Code user settings:
"terminal.integrated.shell.windows": "C:\\cygwin\\bin\\bash.exe", "terminal.integrated.env.windows" {"CHERE_INVOKING": "1"}, "terminal.integrated.shellArgs.windows": ["-l"]
Use Your Compiler
Use your Bash shell or Terminal to cd into the folder/directory where your file is.
Compile it with: gcc -Wall -Wextra -o <NameOfFile> <NameOfFile.c> -Wall
and –Wextra
have to do with listing warnings in your terminal when you compile
Run it with: ./<NameOfFile>
Conclusion
In this article we’ve looked at two ways to install and run a compiler on your machine.
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.