Linux个人开发环境搭建
简介
习惯用云开发机做个人开发环境,云开发机通过云服务提供商购买虚拟实例,安装相应的Linux版本。使用云开发机需要付钱,谁家有活动实惠就买谁家的,意外着可能经常需要迁移环境。重新搭建环境比较麻烦耗时,所以整理下搭建步骤,后面迁移时按流程快速迁移,另外,新环境保持完全一致的标准结构,避免迁移后的不适应感。
购买开发机
去阿里云、百度云、腾讯云、aws购买,大公司的谁家有活动、谁家便宜买谁家的,一般活动只允许买一年,续费可能就要贵很多了。购买虚拟机时选择相应的系统镜像即可,付款后拿到host,以root账户ssh登录。
环境搭建
创建用户
习惯创建rd和work两个账户,在rd下面开发调试,在work下面部署。
groupadd rd
useradd -d /home/rd -g rd -m rd
passwd rd
groupadd work
useradd -d /home/work -g work -m work
passwd work
搭建开发环境
1.切换到rd账户。
su rd
2.创建目录。
apps:测试环境部署。
backup:备份目录。
develop:开发目录。
env:开发环境目录。
tmp:临时目录。
mkdir -p ~/apps ~/backup ~/develop ~/env ~/tmp
3.从原机器scp基础环境远代码包到新机器,并比对签名。
主要是golang、git、vim、lrzsz、zlib这些开发基础环境包,也可以在其官网下载。
mkdir -p ~/backup/dev_env_src
scp /home/rd/backup/dev_env_src/* rd@xx.xx.xx.xx:/home/rd/backup/dev_env_src
4.gcc、g++、make、automake、cmake、tree安装:
这些基础编译工具直接yum执行标准安装。
su root
yum install -y gcc gcc-c++ make automake cmake tree
安装gcc8。
安装scl源:
yum install centos-release-scl scl-utils-build -y
列出scl可用源:
yum list all --enablerepo='centos-sclo-rh'
yum list all --enablerepo='centos-sclo-rh' | grep "devtoolset-"
安装8版本的gcc、gcc-c++、gdb工具链:
yum install -y devtoolset-8-toolchain
scl enable devtoolset-8 bash
5.golang、git、vim、lrzsz、ctags编译安装:
cd /home/rd/backup/dev_env_src
golang:
tar zxvf ./go1.14.1.linux-amd64.tar.gz
mv go ~/env/
zlib(git依赖):
tar zxvf zlib-1.2.11.tar.gz
mkdir ~/env/zlib
cd zlib-1.2.11
./configure --prefix=/home/rd/env/zlib
make -j 2
make install
cd ../
git:
tar zxvf git-2.18.0.tar.gz
mkdir ~/env/git
cd git-2.18.0
./configure --prefix=/home/rd/env/git/ --with-zlib=/home/rd/env/zlib/
make -j 2
make install
cd ../
ncurses(vim依赖,基础库标准安装):
su root
tar zxvf ncurses-6.2.tar.gz
cd ncurses-6.2
./configure
make -j 2
make install
su rd
cd /home/rd/backup/dev_env_src
vim:
tar zxvf vim-8.1.0233.tar.gz
mkdir ~/env/vim
cd vim-8.1.0233
./configure --prefix=/home/rd/env/vim/
make -j 2
make install
cd ../
lrzsz:
tar zxvf lrzsz-0.12.20.tar.gz
mkdir ~/env/lrzsz
cd lrzsz-0.12.20
./configure --prefix=/home/rd/env/lrzsz/
make -j 2
make install
cd ../
ctags:
tar zxvf ctags-5.8.tar.gz
cd ctags-5.8
./configure --prefix=/home/rd/env/ctags/
make -j 2
make install
cd ../
5.bash配置:
vim ~/.bash_profile
source ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
# language
export LANG=zh_CN.UTF-8
# self specific environment
# 为vim支持256色
export TERMINFO=/usr/share/terminfo
# vim
export PATH=$HOME/env/vim/bin:$PATH
# git
export PATH=$HOME/env/git/bin:$PATH
# go
export GOROOT=$HOME/env/go
export GOPATH=$HOME/develop/go-path
export GOBIN=$GOPATH/bin
export PATH=$GOROOT/bin:$GOBIN:$PATH
export GOPROXY=https://goproxy.baidu.com
export GONOSUMDB=\*
export GONOPROXY=\*\*.baidu.com\*\*
alias gopath="cd $GOPATH/src"
# php
#alias php="$HOME/env/php/bin/php -c $HOME/env/php/etc/php.ini"
#alias phppath="cd $HOME/develop/php-path/"
# redis
#export PATH=$HOME/env/redis/bin:$PATH
# lrzsz
export PATH=$HOME/env/lrzsz/bin:$PATH
6.vim配置:
.vim目录:
tar zxvf vim_hide_dir.tar.gz
mv ./home/rd/.vim ~/
分别把vim-go-1.19.zip、Vundle.vim-master.zip、php_funclist.txt cp到对应目录就可以。
├── autoload
│ └── acp.vim
├── bundle
│ ├── vim-go
│ └── Vundle.vim
├── doc
│ ├── acp.jax
│ ├── acp.txt
│ ├── php_funclist.txt
│ └── taglist.txt
└── plugin
├── acp.vim
├── scala.vim
└── taglist.vim
.vimrc配置:
set nocompatible "" not compatible with VI
set mouse=v
"" Encodings and fonts
set encoding=utf-8
set fileencoding=utf-8
"set fileencodings=ucs-bom,gb18030,gbk,gb2312,cp936
set fileencodings=utf-8
set termencoding=utf-8
set langmenu=zh_CN.UTF-8
language messages zh_CN.UTF-8
"" Tab and Backspace
set sw=4
set tabstop=4
set shiftwidth=4
set cindent
set smartindent
set autoindent
set ts=4
set expandtab
set smarttab
:%retab!
set backspace=indent,eol,start "" set backspace
"" Display
set number "" show line number
set ruler "" always show current position
"set cursorline "" highlight the current line
set showcmd
"" Searching
set ignorecase "" search setting
set incsearch
set hlsearch
set showmatch
set history=10
highlight Search term=reverse ctermbg=4 ctermfg=7
"" Syntax and color scheme
syntax on
syntax enable
filetype plugin indent on
"colorscheme torte
"colorscheme default
"highlight Comment ctermfg=grey
"highlight Normal ctermfg=grey ctermbg=darkblue
"
""""""""""" 自动补全命令 """"""""""
autocmd Filetype c set omnifunc=ccomplete#Complete
autocmd Filetype html set omnifunc=htmlcomplete#CompleteTags
autocmd Filetype xml set omnifunc=xmlcomplete#CompleteTags
autocmd Filetype python set omnifunc=pythoncomplete#CompleteTags
autocmd Filetype tex set omnifunc=syntaxcomplete#Complete
"""""""""" 英文拼写检查 """""""""""
" 拼写错误被画红线,比缺省设置更美观 "
" """"""""""""""""""""""""""""""""""
" set spell spelllang=en_us
" setlocal spell spelllang=en_us
" highlight clear SpellBad
" highlight SpellBad term=standout ctermfg=1 term=underline cterm=underline
" highlight clear SpellCap
" highlight SpellCap term=underline cterm=underline
" highlight clear SpellRare
" highlight SpellRare term=underline cterm=underline
" highlight clear SpellLocal
" highlight SpellLocal term=underline cterm=underline
"
au FileType php call PHPFuncList()
function PHPFuncList()
set dictionary-=~/.vim/doc/php_funclist.txt dictionary+=~/.vim/doc/php_funclist.txt
set complete-=k complete+=k
endfunction
" 修改文件自动备份
" if has("vms")
" set nobackup
"else
" set backup
"endif
""""""""""""""""
" taglist ctags
""""""""""""""""
"设置ctags路径
let Tlist_Ctags_Cmd = "/home/rd/env/ctags"
"启动vim后自动打开taglist窗口
"let Tlist_Auto_Open = 1
"不同时显示多个文件的tag,仅显示一个
"let Tlist_Show_One_File = 1
"taglist为最后一个窗口时,退出vim
let Tlist_Exit_OnlyWindow = 1
"taglist窗口显示在左侧,缺省为左侧
let Tlist_Use_Left_Window = 1
"设置taglist窗口大小
let Tlist_WinHeight = 100
let Tlist_WinWidth = 30
"设置taglist打开关闭的快捷键F8
noremap <F8> :TlistToggle<CR>
"更新ctags标签文件快捷键设置
noremap <F6> :!ctags -R<CR>
" vim-go
" """""""""""" END """"""""""""
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle
" " required!
Plugin 'gmarik/Vundle.vim'
Plugin 'fatih/vim-go'
call vundle#end()
7.git配置:
git config –global user.email xxx@xx.com
git config –global user.name xxx
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub 粘到github中,就可以使用ssh了。
8.创建工作目录:
mkdir -p /home/rd/develop/go-path/src /home/rd/develop/php-path /home/rd/develop/tools
TODO
1.标准环境、基础库、通用框架、基础组件,这些都可以抽象整理出来,提升个人效率。