0%

搭建Ubuntu下的开发环境


最近有点闲暇时间,厌倦了windows开发环境,想尝试一下ubuntu下的开发环境。本人Android开发者,也写一点前端,以前家里是mac开发环境,公司是windows开发环境,现在打算把公司的开发环境改为ubuntu,之前也看过ubuntu下搭建Android开发环境的文章,即使这样,也踩了不少的坑,折腾了几天,总算把环境搭建起来了,基本稳定。总的来说ubuntu下的开发环境不像windows和mac那么好搭建,坑点略多,但是搭建成功后运行速度是非常可观的,比起windows快了不少,也不枉费花了这么多时间。接下来总结一下ubuntu下开发的常用软件,插件,以及可能遇到的坑点。


安装系统遇到的问题

安装系统流程比较普通,分区方案网上有很多,不过要注意两点

安装英文版的系统

即使不习惯英文系统也应该在安装系统时选择英文,安装完了再改回中文,因为如果是安装中文版的系统,文件夹的名称会变成下载,文档,音乐,图片...由于ubuntu很多时候用命令行,导致命令行输入经常切换中文不方便,我第一次安装的时候手快选了中文版,以为后面可以改,然而这个目录名是安装系统的时候就建好了的,第二次果断安装英文版

分区的坑

ubuntu虽然可以挂载ntfs分区,但是ide在读取工程目录的时候是只读取/下面的,所以根目录的分区一定不能小

卸载系统自带的软件

有些软件系统自带,但是并不好用或者不会用到的可以卸载掉
以下是卸载清单
libreoffice-common libreoffice(可以换 WPS)
unity-webapps-common Amazon 链接
totem 自带的播放器
rhythmbox 自带的音乐播放器
empathy 自带的即时聊天应用
brasero 自带的光盘刻录器
simple-scan 扫描仪
gnome-mahjongg 对对碰游戏
aisleriot 纸牌游戏
gnome-mines 扫雷游戏
cheese webcam 应用
gnome-sudoku 数独游戏
transmission-common BT 客户端
gnome-orca 屏幕阅读
webbrowser-app 自带的浏览器(这个太难用了,有chrome 和 Firefox)
landscape-client-ui-install landscape 远程控制软件
deja-dup 备份
onboard 屏幕键盘

下面是可以批量卸载的命令
sudo apt-get remove unity-webapps-common;sudo apt-get remove totem;sudo apt-get remove rhythmbox;sudo apt-get remove empathy;sudo apt-get remove brasero;sudo apt-get remove simple-scan;sudo apt-get remove gnome-mahjongg;sudo apt-get remove aisleriot;sudo apt-get remove gnome-mines;sudo apt-get remove cheese;sudo apt-get remove transmission-common;sudo apt-get remove gnome-orca;sudo apt-get remove webbrowser-app;sudo apt-get remove gnome-sudoku;sudo apt-get remove landscape-client-ui-install;sudo apt-get remove onboard;sudo apt-get remove deja-dup;sudo apt-get remove libreoffice-common

apt-get remove –purge xxx # 移除应用及配置
apt-get autoremove # 移除没用的包

apt替换阿里源

图形界面配置

新手推荐使用图形界面配置: 系统设置 -> 软件和更新 选择下载服务器 -> “mirrors.aliyun.com”

手动更改

用你熟悉的编辑器打开:
/etc/apt/sources.list
替换默认的
http://archive.ubuntu.com/为mirrors.aliyun.com
以Ubuntu 14.04.5 LTS为例,最后的效果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
deb https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
## Not recommended
# deb https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse

ubuntu 16.04 配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe

ubuntu 18.04(bionic) 配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

设置中文输入法

sudo add-apt-repository ppa:fcitx-team/nightly
sudo apt-get update
安装fcitx
sudo apt-get install fcitx
安装fcitx的配置工具
sudo apt-get install fcitx-config-gtk
安装fcitx的table-all软件包
sudo apt-get install fcitx-table-al l
安装输入法切换工具
sudo apt-get install im-switch
设置语言选项:将键盘输入法系统由默认的iBus设置为fcitx
安装了搜狗输入法后频繁崩溃,索性就用fcitx自带的,并没觉得有什么不同

命令行相关

bash对应配置文件为.bashrc
zsh对应配置文件为.zshrc
oh-my-zsh是基于zsh的功能做了一个扩展,方便的插件管理、主题自定义,以及漂亮的自动完成效果。比默认的bash好用

安装zsh

sudo apt-get install zsh

安装ohmyzsh

git源码

git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cd oh-my-zsh/tools
./install.sh

curl

sh -c “$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

wget

sh -c “$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)”

修改默认shell

ubuntu下默认的shell是bash,修改它为zsh&ohmyzsh
chsh -s /bin/zsh

配置主题

修改~/.zshrc中的ZSH_THEME

配置插件

修改~/.zshrc中的plugins=(git bundler osx rake ruby)
常用插件
wd 快速进入
zsh-syntax-highlighting 语法高亮
zsh-autosuggestions 历史记录提示
svn
adb
yarn

图形化svn与git管理工具

rabbitvcs

  1. 添加PPA源
    sudo add-apt-repository ppa:rabbitvcs/ppa
    如果导入密钥失败,则在 /etc/apt/sources.list 文件中加入:
    1
    deb http://ppa.launchpad.net/rabbitvcs/ppa/ubuntu **DISTRIBUTION** main
  2. 更新源
    1
    sudo apt-get update
  3. 安装依赖
    1
    sudo apt-get install python-nautilus python-configobj python-gtk2 python-glade2 python-svn python-dbus python-dulwich subversion meld
  4. 安装RabbitVCS
    1
    sudo apt-get install rabbitvcs-cli  rabbitvcs-core rabbitvcs-gedit rabbitvcs-nautilus
  5. 重启文件浏览器
    1
    2
    nautilus -q 
    nautilus

    shadowsocks相关

    作为开发者ss是必不可少的,特别是习惯了google的,完全无法忍受没有梯子的日子,ubuntu下配置shadowsocks稍微有些麻烦。
    首先我们要下载shadowsocks的无图形界面版本,我用过图形界面版qt5,太不稳定了。
    sudo apt update
    sudo apt install python-gevent python-pip
    pip install shadowsocks
    编辑配置文件
    vim /etc/ss.json
    server 服务器地址
    server_port 端口
    local_port 本地端口
    password 密码
    method 加密方式 跟服务器保持一致
    1
    2
    3
    4
    5
    6
    7
    8
    { 
    "server":"server_ip",
    "server_port":30696,
    "local_port":1080,
    "password":"password",
    "timeout":600,
    "method":"rc4-md5"
    }
    ubuntu自带开机启动项设置工具 startupapplications点击add添加
    name和comment随意填写,command填写为sudo sslocal -c /etc/ss.json -d start
    配置好了以后,我们需要修改本机代理,windows、mac都是不需要的
    这里有一个坑点ubuntu18上启动shadowsocks,openssl.py会报错,将此文件中的52行和111行中的cleanup替换为reset,否则可能执行启动命令报错

    全部请求用代理

    SystemSetting->Network->->NetworkProxy
    Method设置为Manual
    sockshost 127.0.0.1 1080,然后Apply System Wide

    添加规则,部分代理

    安装genpac
    sudo apt-get install python-pip
    sudo pip install genpac
    使用genpac生成autoproxy.pac规则文件
    genpac -p “SOCKS5 127.0.0.1:1080” –output=”autoproxy.pac”
    让系统应用规则
    SystemSetting->Network->NetworkProxy
    Method设置为Automatic
    Configuration Url填”file:///home/xxx/autoproxy.pac”,然后Apply System Wide
    chrome和firefox都要安装Proxy SwitchyOmega插件
    方便我们设置自动切换规则

    http代理

    如果是命令行,很多只支持http协议的软件或者工具,我们再配置一次http代理

    安装privoxy

    sudo apt-get install privoxy

    配置privoxy

    打开/etc/privoxy/config
    取消listen-address localhost:8118的代码注释
    找到5.2节
    加入一句
    forward-socks5 / 127.0.0.1:1080 .
    重启privoxy服务
    sudo /etc/init.d/privoxy restart
    开机自启privoxy服务
    sudo /etc/init.d/privoxy start加入到/etc/rc.local文件中的exit 0这句之前
    在profile中写入http代理
    export http_proxy=”127.0.0.1:8118”
    export https_proxy=”127.0.0.1:8118”

Ubuntu软件集合

chrome 开发者必备浏览器,自带有firefox
Typora markdown编辑器
Deepin Screenshot深度截图(Ubuntu Software中安装)
electronic wechat 微信
快速启动ULauncher
Redshift 自动调节屏幕色温
Android studio android开发者都懂
Webstorm 前端开发利器
vscode 微软出的开发神器,轻量级
mpv 播放器
angrySearch文件搜索
ubuntu-tweak 集清理,主题管理,字体管理,热区自定义于一体的软件,可替代ubuntu-tweak-tool,这个软件会默认安装系统自带的浏览器
(2018-5-31 新版的ubuntu18移除了unity桌面,这个没啥用了,可换成gnome-tweak-tool)

ubuntu18 gnome主题定制

定制资源下载
光标: 下载解压后放到/usr/share/icons/目录
GTK主题: 下载解压后放到/usr/share/themes/目录
图标: 下载解压放到/usr/share/icons/目录
shell主题: 下载解压放到/usr/share/themes/目录 (需要安装gnome shell extension)
(使用gnome tweak tool->apperance前面按钮安装zip,会放到~/.local/share/themes下)
重启gnome tweak tool,才可在gnome tweak tool中找到

wps 金山wps有linux版

安装后进入,报字体缺失
下载字体包
百度云http://pan.baidu.com/s/1nuS5U5b 密码:p4vz

  1. 解压
  2. 把wps_symbol_fonts目录拷贝到 /usr/share/fonts/ 目录下
  3. 权限添加
    1
    2
    3
    4
    #cd /usr/share/fonts/
    #chmod 755 wps_symbol_fonts
    #cd /usr/share/fonts/wps_symbol_fonts
    #chmod 644 *
  4. 生成缓存配置信息
    1
    2
    3
    4
    #cd /usr/share/fonts/wps_symbol_fonts
    #mkfontdir
    #mkfontscale
    #fc-cache

    小程序开发工具

    微信开发者工具(微信小程序)linux完美支持
    https://github.com/cytle/wechat_web_devtools

抓包

wireshark
https://blog.csdn.net/xukai871105/article/details/31008635
charles也有linux版

qq 解决方案

优麒麟qq,表情显示不出来且发送错误,版本很老
Wine-QQ-TIM,使用几天后出现电脑无故卡死,输入法切换不了,无法启动等问题
Wine真的不好用,还不如虚拟机
一番折腾后,还是卸载了qq,珍爱生命,远离qq

微信 解决方案 (2019.4.15更新)

  • 目前发现electronic-wechat就是最好的解决方案没有之一,基于web微信用Electron封装并开源
    传送门

    钉钉 解决方案 (2019.4.15更新)

  • 目前发现dingtalk就是最好的解决方案没有之一,基于web钉钉用Electron封装并开源
    传送门

    virtualbox&genymotion

    虚拟机和Android模拟器
    在virtualbox下安装win7,解决ubuntu下无法解决的问题
    安装virtualbox时注意安装ubuntu最新版本,如果开了intel虚拟技术,还是卡开机界面,可能是当前显卡驱动问题,不要选择opensource版本的显卡驱动
    genymotion尽量选择最新的版本,这里有个坑,如果卡死,内存分配尽量大一点

拾色器

前端开发,app开发必不可少的工具
Deepin picker 深度取色器(Ubuntu Software中安装)
添加快捷键:
Settings -> Devices -> Keyboard commond为:/usr/bin/deepin-picker
同理,添加截图的快捷键
Settings -> Devices -> Keyboard commond为:/usr/bin/deepin-screenshot

系统备份

辛苦折腾的系统最好做个备份 ,remastersys这个系统备份工具是不错,但是备份文件大于4g就会备份失败,官方文档也说了这个问题是iso9660的限制,目前无解。
后来发现一个更好用的工具,Timeshift类似mac上的TimeMachine,按备份时间点创建快照,对快照可进行管理,有备份计划等功能,可以实现增强备份和完整备份。

目前就总结到这里,后面如果发现更好用的软件,插件,坑点会持续更新~

  • 2018.11.11爬坑
    Android studio真机调试会报一个错,发现设备无法被识别
    error insufficient permissions for device user in plugdev group are your udev rules wrong
    解决方案:
  1. lsusb命令查出所有通过usb连接pc的设备,找出那个正在调试的读不出型号的设备
    1
    2
    3
    4
    5
    6
    Bus 001 Device 004: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
    Bus 001 Device 003: ID 1bcf:2984 Sunplus Innovation Technology Inc.
    Bus 001 Device 006: ID 2717:9039
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 002 Device 002: ID 046d:c077 Logitech, Inc.
    注意ID后XXXX:XXXX的参数,前一个是idVendor,后一个是idProduct
  2. 创建adb_usb.ini文件,写入idVendor到~/.android/adb_usb.ini,内容格式为0xidVendor
    1
    echo 0x2717> ~/.android/adb_usb.ini
    这一步官网上没有提到,导致后面android.rules文件一直报SUBSYSTEM=="usb"有错
  • 以下步骤可以解决Android studio无法识别设备XXXX[null]的问题
  1. 添加Usb设备配置文件,创建文件并写入以下内容
    1
    2
    sudo vim /etc/udev/rules.d/70-android.rules
    SUBSYSTEM=="usb", ATTRS{idVendor}=="2717", ATTRS{idProduct}=="9039",MODE="0666"
  2. 给配置文件添加权限
    1
    sudo chmod a+rx /etc/udev/rules.d/70-android.rules
  3. 重新加载usb配置规则文件,重启adb服务并查看
    1
    2
    3
    sudo udevadm control --reload-rules && sudo service udev restart && sudo udevadm trigger
    adb kill-server && adb start-server
    adb devices
    此时设备已经可以识别了