首先,对Ubuntu 14.04 LTS进行源更新,摘自下述链接:
http://chenrongya.blog.163.com/blog/static/8747419620143185103297/
对其源列表进行备份
1 sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
注: lsb_release -a 查看ubuntu版本号
用编辑器gedit进行打开 sources.list
1 sudo gedit /etc/apt/sources.list
打开后,将下列服务器地址复制粘帖在最后,保存并关闭:
deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
设置好上述后,对ubuntu 源进行更新:
sudo apt-get update
运行下述,即可实现g++工具的安装
sudo apt-get install g++
g++安装完成。
创建一个简单的cpp文件
1、打开终端:
Ctrl + Alt + T
2、创建一个main.cpp文件
先创建一个文件夹(例如:CPP)
mkdir CPP
在文件CPP下,创建一个main.cpp文件
cd CPP
touch main.cpp
创建完成后,打开main.cpp
gedit main.cpp
3、在main.cpp文件中输入:
1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 cout<<"hello This is My first CPlusPlus!"<<endl; 6 return 0; 7 }
4、运行main.cpp 文件
1 g++ main.cpp -o test
2 ./test
运行,输出。