一尊蚁、C
1.更新數(shù)據(jù)源
apt update
2.下載gcc編譯器并查看是否安裝成功
apt install gcc
gcc --version
3.使用vim編寫
vim main.c
編寫如下代碼
#include <stdio.h>
int main(){
printf("hello world!\n");
return 0;
}
4.編譯并運(yùn)行
##生成c語言源代碼的目標(biāo)代碼
gcc -c main.c -o main.o
##將目標(biāo)代碼編譯成可執(zhí)行文件
gcc -o main.o
##運(yùn)行
./main
運(yùn)行成功會看到輸出了hello world!
二循未、Java
1.更新數(shù)據(jù)源
apt update
2.下載jdk
apt install openjdk-17-jdk -y
java -version
3.使用vim編寫
vim main.java
編寫如下代碼
public class main {
public static void main(String[] args) {
System.out.println("hello java!");
}
}
4.編譯并運(yùn)行
##編譯成java源代碼的執(zhí)行文件
javac main.java
##運(yùn)行
java main
三泼返、Go
1.更新數(shù)據(jù)源
apt update
2.安裝goland
apt install golang
go version
3.使用vim編寫
vim main.go
package main;
func main(){
println("hello go!");
}
4.編譯并運(yùn)行
##將golang源代碼編譯成可執(zhí)行文件
go build -o main_go main.go
##運(yùn)行
./main_go
四、Python
1.更新數(shù)據(jù)源
apt update
2.安裝python并查看是否安裝成功
apt install python3
python3 --version
注意:大多數(shù)Linux發(fā)行版已經(jīng)默認(rèn)安裝了Python
3.使用vim編寫
vim hello.py
print("hello python!");
4.運(yùn)行
python3 hello.py
五币叹、Rust
1.安裝rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
cargo --version
2.創(chuàng)建新項(xiàng)目
cargo new hello-rust
這會生成一個名為 hello-rust 的新目錄润歉,其中包含以下文件:
hello-rust
|- Cargo.toml
|- src
|- main.rs
Cargo.toml 為 Rust 的清單文件。其中包含了項(xiàng)目的元數(shù)據(jù)和依賴庫颈抚。
src/main.rs 為編寫應(yīng)用代碼的地方踩衩。
cargo new 會生成一個新的"Hello, world!"項(xiàng)目!我們可以進(jìn)入新創(chuàng)建的目錄中贩汉,執(zhí)行下面的命令來運(yùn)行此程序
cd hello-rust
cargo run
3.添加依賴
現(xiàn)在來為應(yīng)用添加依賴驱富。可以在 crates.io匹舞,即 Rust 包的倉庫中找到所有類別的庫褐鸥。在 Rust 中,通常把包稱作"crates"
在本項(xiàng)目中赐稽,使用了名為 ferris-says 的庫
在 Cargo.toml 文件中添加以下信息(從 crate 頁面上獲取):
[dependencies]
ferris-says = "0.3.1"
接著運(yùn)行:
cargo build
之后 Cargo 就會安裝該依賴
4.一個 Rust 小應(yīng)用
cd src
vim main.rs
現(xiàn)在我們用新的依賴庫編寫一個小應(yīng)用,在 main.rs 中添加以下代碼:
use ferris_says::say;
use std::io::{stdout, BufWriter};
fn main() {
let stdout = stdout();
let message = String::from("Hello fellow Rustaceans!");
let width = message.chars().count();
let mut writer = BufWriter::new(stdout.lock());
say(&message, width, &mut writer).unwrap();
}
保存完畢后運(yùn)行
cargo run
六叫榕、Node.js
1.更新數(shù)據(jù)源
apt update
2.安裝
apt install nodejs -y
node -v
3.使用vim編寫
vim hello.js
console.log("hello node!");
4.運(yùn)行
node hello.js
七、C++
1.更新數(shù)據(jù)源
apt update
2.安裝g++
apt install g++
g++ --version
3.使用vim編寫
vim hello.cpp
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
4.編譯并運(yùn)行
##生成c++源代碼的目標(biāo)代碼
g++ -c hello.cpp -o hello.o
##將目標(biāo)代碼編譯為可執(zhí)行文件
g++ hello.o -o hello
##運(yùn)行
./hello