1.换源
编辑sources.list文件:
sudo gedit /etc/apt/sources.list
将内容替换成阿里源:
deb http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe
最后进行更新源:
sudo apt-get update
2.查看并解除端口占用
由于在服务器中经常写socket的程序,有时候ctrl+c以后重新运行提示端口被占用,如果等候或者重启的话就很麻烦了,解决办法就是查看端口占用并解除。
查看指定端口,可以结合grep命令:
netstat -ap | grep 6666
也可以使用lsof命令:
lsof -i:6666
若要关闭使用这个端口的程序,使用kill + 对应的pid
kill -9 PID号
ps:kill就是给某个进程id发送了一个信号。默认发送的信号是SIGTERM,而kill -9发送的信号是SIGKILL,即exit。exit信号不会被系统阻塞,所以kill -9能顺利杀掉进程。
3.apt-install 出现以下错误:
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
解决:
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock