在我們安裝完ubuntu server之後,這個系統還不算完善,因爲它缺少很多重要的軟件及包的支持。下面,我以ubuntu 13.04的服務器開發環境搭建作爲例子來介紹一下我們如何使用ubuntu搭建一個基本夠用的linux開發環境。
一. 重新配置ubuntu的apt源
1. 選擇apt源的原則
首選國內比較穩定的源。
其次,運營商線路因素的考慮。比如我是電信用戶,我就用ubuntu.cn99.com提供的源,這個源對於電信用戶而言,速度比較好。
現在,我確定使用CN99提供的鏡像。
2. 確定ubuntu的發佈代碼(distribute CODENAME)
現在我們來修改apt的配置文件,修改配置文件之前,需要確定ubuntu版本的發佈代碼。
什麼是發佈代碼:每一個ubuntu版本發佈的時候,都會爲該版本確定一個發佈代碼,這個發佈代碼的目的就是給該版本取一個文字名字。可參考https://wiki.ubuntu.com/Releases
比如ubuntu 13.04的發佈代碼是raring,在我們配置apt源的時候就需要這個發佈代碼。
apt客戶端會告訴apt源服務端,我們的ubuntu是raring(也就是ubuntu 13.04),這樣,源服務端就會給我們對應版本13.04的各種包及軟件。
所以,我們需要在最開始就確定ubuntu的發佈代碼。
weizhulinux@ubuntu:~$lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 13.04
Release: 13.04
Codename: raring
此時,我們獲取到我們的ubuntu 13.04對應的發佈代碼,也就是CODENAME是raring。
同樣的方法可以得知ubuntu 10.10對應的發佈代碼是maverick。
3. 修改apt的配置文件/etc/apt/sources.list
配置文件的格式如下
deb http://some-apt-source/ubuntu/CODENAME main restricted universe multiverse
deb http://some-apt-source/ubuntu/CODENAME-security main restricted universe multiverse
deb http://some-apt-source/ubuntu/CODENAME-updates main restricted universe multiverse
deb http://some-apt-source/ubuntu/CODENAME-proposed main restricted universe multiverse
deb http://some-apt-source/ubuntu/CODENAME-backports main restricted universe multiverse
我現在拿我喜歡的CN99以及我們查到的13.04對應的發佈代碼來修改這個配置文件,把apt源指向CN99,並且指定我們的系統版本是raring,這樣,在升級的時候,apt客戶端就會去我們想去的CN99鏡像上去取關於13.04對應的各種包及軟件。
我自己的sources.list配置文件內容如下
weizhulinux@ubuntu:~$ cat /etc/apt/sources.list
deb http://ubuntu.cn99.com/ubuntu/raring main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ raring-security main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ raring-updates main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ raring-proposed main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ raring-backports main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ raring main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ raring-security main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ raring-updates main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ raring-proposed main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ raring-backports main restricted universe multiverse
weizhulinux@ubuntu:~$
4. 系統升級
好了,修改好了apt源的配置文件,接下來進行系統大升級
weizhulinux@ubuntu:~$ sudo aptitude update
[sudo] password for weizhulinux:
Hit http://ubuntu.cn99.com raring Release.gpg
Get: 1 http://ubuntu.cn99.com raring-security Release.gpg [933 B]
Get: 2 http://ubuntu.cn99.com raring-updates Release.gpg [933 B]
這一步的目的是獲取鏡像上關於raring版本軟件包的信息,僅僅是信息,並非軟件包本身。把這些信息取回到本地供後續使用。
二. 給系統三個重要能力
2.1 讓系統具備ssh遠程連接的能力
因爲我們後續要使用security連接到服務器來坐開發或者運維,直接使用console的話,會比較麻煩。新安裝的ubuntu並不包含ssh服務,所以我們要在這一步安裝ssh。
weizhulinux@ubuntu:~$ aptitude install ssh
這個ssh包含了ssh服務端和客戶端兩個功能,安裝完ssh,我們查看一下系統,會發現ssh服務已經啓動,並且監聽在默認的22端口。
weizhulinux@ubuntu:~$ netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
2.2 安裝完整版本的vim
在舊版本的ubuntu中,完整版本的vim包名字是vim-full,但在安裝13.04版本的ubuntu過程中,我發現已經沒有vim-full這個名字,直接使用vim就可以了,這個我就不深究了
weizhulinux@ubuntu:~$ sudo aptitude install vim
至於vim的配置及使用,我會在另外的文章中詳細介紹。
2.3 安裝lrzsz
目的是爲了在後續的開發過程中,方便的使用security和服務器互相上傳下載小文件,注意,是小文件哦
weizhulinux@ubuntu:~$ sudo aptitude install lrzsz
三. 安裝C/C++程序的開發包
這一步需要安裝的東西比較多,爲了方便起見,可以直接切換到root用戶下操作,避免太多次輸入密碼,好麻煩的
//安裝主要編譯工具 gcc, g++等等
apt-get install build-essential
apt-get install autoconf automake1.9
apt-get install flex bison
//安裝C語言函數man文檔
apt-get install manpages
apt-get install manpages-de
apt-get install manpages-de-dev
apt-get install manpages-dev
//安裝相關文檔
apt-get install binutils-doc cpp-doc gcc-doc glibc-docstl-manual
四. 結束
安裝過程中有時我使用apt-get,有時使用aptitude,在使用install指令的時候,這兩個命令沒有任何區別。好了,到這裏基本就結束了,現在你可以方便的使用gcc及make等等工具來編譯並調試你的程序了,後續我會介紹安裝更多強大的開發過程中有用的觀察服務器程序運行的工具。