There are three primary approaches to setting up a Linux environment:
| Method | Description |
|---|---|
| Dual Boot | Installing Linux directly on physical hardware alongside another OS. This is generally not recommended due to poor desktop usability. |
| Virtual Machine | Running Linux inside software like VMWare. This can be problematic due to software bugs and environment instability. |
| Cloud Server | Renting a instance from providers like Alibaba Cloud, Tencent Cloud, or Huawei Cloud. This is the preferred method as it avoids local configuration issues and allows public internet access for deployed applications. |
Provisioning a Cloud Instance
Using Tencent Cloud as an example (the process is similar for other providers):
- Navigate to the official provider website (e.g.,
https://cloud.tencent.com/). - Select Lighthouse (Lightweight Application Server) or ECS.
- Choose a cost-effective configuration. Huawei Cloud often offers lower prices, but the steps below apply to Tencent Cloud.
- Configuration Settings:
- Region: Select the location closest to you.
- Image: Select CentOS 7.6.
- Once purchased, access the console. Note the Public IP Address highlighted in the interface.
- Security: Click Reset Password to set a strong
rootpassword. A complex password is crucial to prevent unauthorized access.
Essential Connection Details
Ensure you have the following three pieces of information ready:
| Credential | Value |
|---|---|
| Public IP | The external IP address of your instance |
| Username | root (default administrator) |
| Password | The strong password you just set |
Connecting via SSH Client
Download a terminal emulator like XShell (look for the Free for Home/School version).
- Open XShell and click New to create a session.
- Name: Enter any identifier (e.g., "MyCentOS").
- Host: Enter the Public IP of your cloud server.
- Click Connect. When prompted, enter the username (
root) and the password. - Successful login will display a shell prompt (e.g.,
[root@hostname ~]#).
Writing a Simple C Program
With the environment ready, verify functionality by compiling a basic C script.
1. Create the source file
Use touch to generate an empty file.
touch demo.c
2. Edit the file
Open the file using the vi editor.
vi demo.c
- Press
ito enter Insert Mode. - Write your code:
#include <stdio.h>
int main() {
printf("Environment setup successful!\n");
return 0;
}
- Press
ESCto exit Insert Mode. - Type
:wqand hit Enter to write (save) and quit.
3. Inspect the file
Use cat to display the contents of the file to verify.
cat demo.c
4. Compile the code
Use gcc to compile. The -o flag specifies the name of the output executable (otherwise it defaults to a.out).
gcc demo.c -o output_bin
5. Execute the program Run the generated binary using the relative path.
./output_bin