Linux是 Java, PHP, Python等非 .NET, 非IOS开发人员的操作系统。
我们务必要在日常中使用它。
虽然现在安装软件的方式越来越简单, 使用 yum install
(CentOS) , apt-get install
(Ubuntu) 就可以安装,
- 优点: 省去了 编译的环节。
- 缺点: 大家做了这个事儿, 不知道是如何作成的( 缺少了解细节)
- 致命缺点: 有时候安装不了。(比如 远程的源没有这个安装包)
所以, 我们还是要掌握: 经典的 LINUX的 安装方式。 简称 make install
方法。
- 下载源代码。 (使用
wget
等方式,把源代码下载到本地) - 配置 (运行:
./configure --prefix=/path_to_install
) - 编译 (
$ make
) - 安装。 (
$ make install
)
Ubuntu 16.04 LTS
上无法直接安装VIM。 (在某些时候) ,会报错:
siwei@hp:~$ sudo apt-get install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
vim : Depends: vim-common (= 2:7.4.1689-3ubuntu1) but 2:7.4.1689-3ubuntu1.1 is to be installed
E: Unable to correct problems, you have held broken packages.
提示说依赖包是有冲突的。 这也是 apt-get 最常见的问题。
所以, 我们要使用 经典的方式。
通过google, 我们找到了源代码的地址是: ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2
那么, 我们就用 wget
这个命令来获取它。
siwei@hp:~$ wget ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2
--2016-09-09 09:24:22-- ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2
=> ‘vim-7.3.tar.bz2’
Resolving ftp.vim.org (ftp.vim.org)... 145.220.21.40, 2001:67c:6ec:221:145:220:21:40
Connecting to ftp.vim.org (ftp.vim.org)145.220.21.40:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD (1) /pub/vim/unix ... done.
==> SIZE vim-7.3.tar.bz2 ... 9080692
==> PASV ... done. ==> RETR vim-7.3.tar.bz2 ... done.
Length: 9080692 (8.7M) (unauthoritative)
vim-7.3.tar.bz2 100%[===============================>] 8.66M 1.66MB/s in 5.2s
2016-09-09 09:24:31 (1.66 MB/s) - ‘vim-7.3.tar.bz2’ saved [9080692]
2. 解压缩。
使用这个命令来 解压缩 bz2文件:
$ tar xvjf vim-7.3.tar.bz2
获得下列文件:
# 一堆文件, 省略
vim73/pixmaps/tb_cut.xpm
vim73/pixmaps/tb_minwidth.xpm
vim73/pixmaps/tb_maxwidth.xpm
vim73/pixmaps/info.xpm
vim73/vimdir.info
vim73/libs/
vim73/libs/arp.library
vim73/vimtutor.com
vim73/README_extra.txt
vim73/README_vms.txt
使用 ls
命令看一下:
$ ls
configure nsis README_bindos.txt README_src.txt src
Contents pixmaps README_dos.txt README.txt src.info
Contents.info README_amibin.txt README_extra.txt README.txt.info uninstal.txt
csdpmi4b.zip README_amibin.txt.info README_mac.txt README_unix.txt vimdir.info
farsi README_amisrc.txt README_ole.txt README_vms.txt Vim.info
Filelist README_amisrc.txt.info README_os2.txt README_w32s.txt vimtutor.bat
libs README_ami.txt README_os390.txt runtime vimtutor.com
Makefile README_ami.txt.info README_srcdos.txt runtime.info Xxd.info
3. 开始安装
3.1 配置: configure
假设,源目录是: ~/tmp/vim73
, 我们需要把它安装到 /usr/local/vim73
这个目录下, 就可以使用下面的 configure --prefix=/usr/local/vim73
命令:
liyun@hp:~/tmp/vim73$ ./configure --prefix=/usr/local/vim73
可以看到, 程序开始了各种配置:
configure: creating cache auto/config.cache
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
# 一堆信息。。。省略
checking whether stack_t has an ss_base field... no
checking --with-tlib argument... empty: automatic terminal library selection
checking for tgetent in -lncurses... no
checking for tgetent in -ltermlib... no
checking for tgetent in -ltermcap... no
checking for tgetent in -lcurses... no
no terminal library found
checking for tgetent()... configure: error: NOT FOUND!
You need to install a terminal library; for example ncurses.
Or specify the name of the library with --with-tlib.
可以看到, 上面的结尾,有提示错误
no terminal library found
checking for tgetent()... configure: error: NOT FOUND!
You need to install a terminal library; for example ncurses.
Or specify the name of the library with --with-tlib.
通过google, 我们发现了这个答案(大神在大部分时候解决问题也是要靠 google的 ): http://askubuntu.com/questions/158344/no-terminal-library-found-when-compiling-vim
于是安装这个第三方包(使用apt-get 方式):
$ sudo apt-get install ncurses-dev
根据提示输入密码:
[sudo] password for siwei:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libncurses5-dev' instead of 'ncurses-dev'
The following additional packages will be installed:
libtinfo-dev
Suggested packages:
ncurses-doc
The following NEW packages will be installed:
libncurses5-dev libtinfo-dev
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 252 kB of archives.
After this operation, 1,461 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 libtinfo-dev amd64 6.0+20160213-1ubuntu1 [77.4 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 libncurses5-dev amd64 6.0+20160213-1ubuntu1 [175 kB]
Fetched 252 kB in 0s (321 kB/s)
Selecting previously unselected package libtinfo-dev:amd64.
(Reading database ... 154467 files and directories currently installed.)
Preparing to unpack .../libtinfo-dev_6.0+20160213-1ubuntu1_amd64.deb ...
Unpacking libtinfo-dev:amd64 (6.0+20160213-1ubuntu1) ...
Selecting previously unselected package libncurses5-dev:amd64.
Preparing to unpack .../libncurses5-dev_6.0+20160213-1ubuntu1_amd64.deb ...
Unpacking libncurses5-dev:amd64 (6.0+20160213-1ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libtinfo-dev:amd64 (6.0+20160213-1ubuntu1) ...
Setting up libncurses5-dev:amd64 (6.0+20160213-1ubuntu1) ...
再次运行 ./configure --prefix=/usr/local/vim73
发现,可以正常 配置了:
# 前面一堆信息。。。
checking for setjmp.h... yes
checking for GCC 3 or later... yes
checking whether we need -D_FORTIFY_SOURCE=1... yes
configure: updating cache auto/config.cache
configure: creating auto/config.status
config.status: creating auto/config.mk
config.status: creating auto/config.h
然后运行 $ make
编译后的 程序, 运行起来是 100% 与本机兼容的。
在刚接触Linux的时候,我曾经分到过一台服务器。一开始, 使用 yum-install
的方式, 安装ruby , 各种报错, 各种错误都莫名其妙。
于是, 我就 使用 make install
的方式安装(编译源代码的方式),所有错误瞬间消失。
下面就是 $ make
后的各种信息:
# 上千行日志 ,略
OLD_PO_FILE_INPUT=yes msgfmt -v -o sk.cp1250.mo sk.cp1250.po
1632 translated messages.
OLD_PO_FILE_INPUT=yes msgfmt -v -o uk.cp1251.mo uk.cp1251.po
1772 translated messages.
OLD_PO_FILE_INPUT=yes msgfmt -v -o zh_CN.cp936.mo zh_CN.cp936.po
1637 translated messages, 3 fuzzy translations.
make[2]: Leaving directory '/home/liyun/tmp/vim73/src/po'
make[1]: Leaving directory '/home/liyun/tmp/vim73/src'
编译完了( 编译过程中出现的各种 WARNING 都可以无视, 只要这个警告或者错误,不会打断 编译的过程, 你编译出来的程序, 就可以使用)
3.3 安装: make install
这就是 把编译好的 文件, 复制到目的地文件夹的过程
# 太长,省略掉
cp ../runtime/vim48x48.png /usr/local/vim73/share/icons/hicolor/48x48/apps/gvim.png; \
fi
if test -d /usr/local/vim73/share/icons/locolor/32x32/apps -a -w /usr/local/vim73/share/icons/locolor/32x32/apps \
-a ! -f /usr/local/vim73/share/icons/locolor/32x32/apps/gvim.png; then \
cp ../runtime/vim32x32.png /usr/local/vim73/share/icons/locolor/32x32/apps/gvim.png; \
fi
if test -d /usr/local/vim73/share/icons/locolor/16x16/apps -a -w /usr/local/vim73/share/icons/locolor/16x16/apps \
-a ! -f /usr/local/vim73/share/icons/locolor/16x16/apps/gvim.png; then \
cp ../runtime/vim16x16.png /usr/local/vim73/share/icons/locolor/16x16/apps/gvim.png; \
fi
make[1]: Leaving directory '/home/siwei/tmp/vim73/src'
然后,我们就可以看到, 在对应目录下( 还记得前面的 ./configure --prefix=/usr/local/vim73 )
使用 ls -al
命令来显示 目的地文件夹的内容, 可以看到,该有的都有了:
siwei@hp:/usr/local/vim73/bin$ ls -al
total 1644
drwxr-xr-x 2 root root 4096 9月 9 09:38 ./
drwxr-xr-x 4 root root 4096 9月 9 09:38 ../
lrwxrwxrwx 1 root root 3 9月 9 09:38 ex -> vim*
lrwxrwxrwx 1 root root 3 9月 9 09:38 rview -> vim*
lrwxrwxrwx 1 root root 3 9月 9 09:38 rvim -> vim*
lrwxrwxrwx 1 root root 3 9月 9 09:38 view -> vim*
-rwxr-xr-x 1 root root 1652408 9月 9 09:38 vim*
lrwxrwxrwx 1 root root 3 9月 9 09:38 vimdiff -> vim*
-rwxr-xr-x 1 root root 2084 9月 9 09:38 vimtutor*
-rwxr-xr-x 1 root root 14840 9月 9 09:38 xxd*
在这个目录下, 运行 ./vim :
~
~
~ VIM - Vi IMproved
~
~ version 7.3
~ by Bram Moolenaar et al.
~ Vim is open source and freely distributable
~
~ Help poor children in Uganda!
~ type :help iccf<Enter> for information
~
~ type :q<Enter> to exit
~ type :help<Enter> or <F1> for on-line help
~ type :help version7<Enter> for version info
看到了vim 欢迎页面。就表示, 安装好了。
最后, 为了不需要每次运行, 都输入完整路径 (/usr/local/vim73/bin/vim
), 我们就把它加入到 我们的 PATH 变量中。
$ nano ~/.bashrc
在该文件最后加一句:
export PATH="/usr/local/vim73/bin:$PATH"
然后退出Terminal, 重新进, 输入 vim
就可以了!
热门评论
其实这就是传说当中的源码编译安装!
感谢楼主的无私分享!
问下,linux下怎么访问Google