一步步搭建ubuntu server console(控制台,字符模式)开发环境

在我们安装完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等等工具来编译并调试你的程序了,后续我会介绍安装更多强大的开发过程中有用的观察服务器程序运行的工具。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章