Ubuntu常用系统维护
前言
参考
记录
ubuntu多版本共存
升级node
firacode
intel显卡驱动
开机启动脚本(需要sudo)
给应用程序加上图标
windows和ubuntu时间不一致
查看未安装的deb包信息
查看蓝牙运行情况
查看输入设备
Chrome Flashplayer问题
常用chrome配置入口
FlashPlayer outdate
01.org gpg error
压缩与解压
zip
tar
tar.gz
tar.bz2
更多
clinfo查看自己opencl情况
pip install
彻底删除一个包
查找含有某文件的包
pip uninstall
Hash sum mismatch
不断要你上报错误
显示包的版本和依赖信息
手动创建swap文件分区
设置开机启动程序
在live cd 下为某磁盘安装grub
挂载
更改主显示器
查看设备
grub 图形化编辑
查找 package
查询链接库依赖项
删除文件夹
查找包
卸载包
卸载软件
grub
修改hosts文件
Choose server
su 命令失败
环境变量
更新
安装
更改计算机名
网络远程登陆工具
查看网速
启动器上应用程序图标为灰色问号?
处理包冲突问题技巧
Getting Help:
Umet dependencies——软件安装包冲突时的解决思路
关于PPAs(Personal Package Archive)
Disable:
Purge:
Remove:
Preventive Measures:
双硬盘同引导双系统
重新分区的问题
装系统实践
缺少库文件
前言
- 纯粹笔记,以防忘记
参考
记录
ubuntu多版本共存
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.8 100
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-5.0 1000
update-alternatives --install /usr/bin/clang++ clang /usr/bin/clang-3.8 100
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.8 100
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-5.0 1000
update-alternatives --config clang
update-alternatives --config clang++
# 更新clang-format到6.0
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-6.0 1000
sudo update-alternatives --install /usr/bin/clang-format-diff clang-format-diff /usr/bin/clang-format-diff-6.0 1000
升级node
# 我先损坏了npm
# 不要在node升级前升级npm,会执行出问题
sudo rm -r /usr/local/lib/node_modules/npm
npm -v
sudo npm cache clean -f
sudo npm install -g n
sudo n stable/latest #此处用latest
# 解决sudo npm -g install没响应/出错
sudo npm install -g install
sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
# 使用cnmp来解决问题
sudo cnpm install
# 实在不行了,彻底卸载
sudo apt-get remove --purge nodejs
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/include/node*
sudo rm -rf /usr/local/bin/node*
# 再安装
sudo npm i -g bash-language-server
# 继续探索
sudo npm i -g node-gyp
sudo npm -i -d
sudo chown -R $USER:$(id -gn $USER) /home/zs/.config
sudo npm config list
# 解决node-gyp rebuild失败问题
sudo npm cache clean -f
sudo npm install npm -g
sudo npm uninstall node-gyp -g
sudo npm uninstall node-gyp
sudo npm install node-gyp -g
# 无果,折腾一晚上放弃了,不装bash这玩意儿了
# 用cnpm安装好像可以,不过有一个包下载不到
# 浏览器下载然后移动到/usr/local/lib/node_modules/XXX里面,然后再安装
# 找个时间试一下
firacode
sudo add-apt-repository ppa:gertvdijk/firacode
sudo apt install fonts-firacode
intel显卡驱动
wget https://download.01.org/gfx/ubuntu/16.04/main/pool/main/i/intel-graphics-update-tool/intel-graphics-update-tool_2.0.2_amd64.deb
sudo dpkg -i intel-graphics-update-tool_2.0.2_amd64.deb
sudo apt-get install -f
sudo intel-graphics-update-tool
wget $(echo "https://download".01.org/gfx/RPM-GPG-GROUP-KEY-ilg) -O - | sudo apt-key add - sudo apt-get update
开机启动脚本(需要sudo)
sudo gedit /etc/rc.local
给应用程序加上图标
sudo gedit /usr/share/applications/understand.desktop
# 开始编辑
[Desktop Entry]
Type=Application
Name=understand
Icon=/home/zs/opt/scitools/bin/linux64/understand_64.png
Exec=/home/zs/opt/scitools/bin/linux64/understand
Terminal=false
Categories=Application;Programming;
# 第一行是必须的,就像shell脚本要加入#!/bin/bash一样,用于系统识别
# 第二行Type一般填写Application就可以了
# 第三行Name自己随意填,用于显示和搜索
# 第四行Icon是指应用图标的路径
# 第五行Exec是指应用可执行文件路径
# 第六行Terminal表示启动时是否需要显示终端,建议设置为false
# 第七行是指这个应用的分类,即开始菜单中的位置,如上设置的话,点击开始菜单,进Programming类就可以找到这个应用了
windows和ubuntu时间不一致
timedatectl set-local-rtc 1 --adjust-system-clock
查看未安装的deb包信息
dpkg -I xxx.deb
查看蓝牙运行情况
bluetoothctl
查看输入设备
cd /dev/input
Chrome Flashplayer问题
常用chrome配置入口
chrome://plugin
# 在这儿设置flashplayer一直启动
chrome://components
chrome://settings
FlashPlayer outdate
sudo apt install adobe-flashplugin
sudo mv ./libpepflashplayer.so /usr/lib/adobe-flashplugin/
sudo chown root:root /usr/lib/adobe-flashplugin/libpepflashplayer.so
- 上面方法没解决
- 下面方法是到浏览器配置文件修改
cd /home/zs/.config/google-chrome/PepperFlash/
mkdir 24.0.0.186
cd ./24.0.0.186
# 将从Adobe官网下载的pep-flashplayer文件夹所有文件移动到这一目录
sudo gedit /usr/share/applications/google-chrome.desktop
Exec=/usr/bin/google-chrome-stable %U --ppapi-flash-path=/home/zs/.config/google-chrome/PepperFlash/24.0.0.186/libpepflashplayer.so --ppapi-flash-version=24.0.0.186
- 注意:由于不明原因,./.config中的浏览器flashplayer文件夹经常被清空,故按以下格式修改,这种方法是最简便的
Exec=/usr/bin/google-chrome-stable %U --ppapi-flash-path=/usr/lib/adobe-flashplugin/libpepflashplayer.so --ppapi-flash-version=24.0.0.186
01.org gpg error
wget --no-check-certificate https://download.01.org/gfx/RPM-GPG-KEY-ilg-4 -O - | sudo apt-key add -
压缩与解压
zip
# 它最大的优点就是在不同的操作系统平台,比如Linux, Windows以及Mac OS上使用。缺点就是支持的压缩率不是很高,而tar.gz和tar.gz2在压缩率方面做得非常好
zip -r archive_name.zip directory_to_compress
unzip archive_name.zip
tar
# Tar是在Linux中使用得非常广泛的文档打包格式。它的好处就是它只消耗非常少的CPU以及时间去打包文件,他仅仅只是一个打包工具,并不负责压缩。
tar -cvf archive_name.tar directory_to_compress
tar -xvf archive_name.tar.gz
tar.gz
# 这种格式是我使用得最多的压缩格式。它在压缩时不会占用太多CPU的,而且可以得到一个非常理想的压缩率。
tar -zcvf archive_name.tar.gz directory_to_compress
tar -zxvf archive_name.tar.gz
tar -zxvf archive_name.tar.gz -C /tmp/extract_here/
tar.bz2
# 这种压缩格式是我们提到的所有方式中压缩率最好的。当然,这也就意味着,它比前面的方式要占用更多的CPU与时间。
tar -jcvf archive_name.tar.bz2 directory_to_compress
tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/
更多
tar –cvf jpg.tar *.jpg //将目录里所有jpg文件打包成tar.jpg
tar –czf jpg.tar.gz *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用gzip压缩,生成一个gzip压缩过的包,命名为jpg.tar.gz
tar –cjf jpg.tar.bz2 *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用bzip2压缩,生成一个bzip2压缩过的包,命名为jpg.tar.bz2
tar –cZf jpg.tar.Z *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用compress压缩,生成一个umcompress压缩过的包,命名为jpg.tar.Z
rar a jpg.rar *.jpg //rar格式的压缩,需要先下载rar for linux
zip jpg.zip *.jpg //zip格式的压缩,需要先下载zip for linux
tar –xvf file.tar //解压 tar包
tar -xzvf file.tar.gz //解压tar.gz
tar -xjvf file.tar.bz2 //解压 tar.bz2
tar –xZvf file.tar.Z //解压tar.Z
unrar e file.rar //解压rar
unzip file.zip //解压zip
clinfo查看自己opencl情况
sudo apt install clinfo
pip install
sudo -H pip install --upgrade pip
彻底删除一个包
sudo apt remove --purge libaria
- 这会删除库文件和配置文件
查找含有某文件的包
apt-file search 'libgfortran.so.'
pip uninstall
sudo python setup.py install --record files.txt
cat files.txt | xargs sudo rm -rf
Hash sum mismatch
sudo rm -rf /var/lib/apt/lists/*
sudo apt-get update
不断要你上报错误
sudo rm /var/crash/*
reboot
显示包的版本和依赖信息
apt-cache showpkg libboost-all-dev
手动创建swap文件分区
cd /
sudo mkdir swap
cd swap/
sudo dd if=/dev/zero of=swapfile bs=1M count=16k
# 安装16G空间
sudo mkswap swapfile
sudo swapon swapfile
# 如果需要卸载
# sudo swapoff swapfile
# 一直挂载,需要写入/etc/fstab文件
sudo gedit /etc/fstab
# 添加下一行
/swap/swapfile swap swap defaults 0 0
设置开机启动程序
- startup applications
在live cd 下为某磁盘安装grub
- 从live cd 进入ubuntu
sudo su
fdisk -l
mount /dev/sdc1
这是某磁盘ubuntu 启动分区
grub-install --root-directory=/mnt /dev/sdc
重启电脑进入该磁盘,会报错,但可以正常进入ubuntu,然后在该系统中更新即可!
sudo update-grub
挂载
sudo mount -o loop -t hfsplus imagefile.img /mnt
更改主显示器
xrandr
查看显示器详细信息
xrandr --output DFP5 --auto --primary
查看设备
ls /dev/ | grep video
grub 图形化编辑
```
sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer
查找 package
dpkg -l | grep xmind
查询链接库依赖项
.../platforms$ ldd libqxcb.so
删除文件夹
sudo rm -rf ./Robai/
查找包
apt-cache search pcl
卸载包
sudo dpkg -r pcl
卸载软件
sudo apt-get remove ros-indigo-moveit-full
grub
sudo cp /etc/default/grub /etc/default/grub.bak
sudo gedit /etc/default/grub
GRUB_DEFAULT=
GRUB_TIMEOUT=5
sudo update-grub
修改hosts文件
sudo gedit /etc/hosts
sudo rcnscd restart
sudo apt-get install nscd
sudo /etc/init.d/nscd restart
127.0.1.1 zsUbuntu
Choose server
- Choose the ubuntu server sjtu.edu.cn
su 命令失败
- 试试sudo su进入root模式
环境变量
env
查看环境变量
set
查看所有变量(环境变量+自定义变量)
echo ${PATH}
PATH="$PATH":'/home/zs/VSCode-linux-x64'
添加路径至PATH环境变量
路径可以不加单引号
echo $$
当前线程的PID号码
echo $?
上个命令的回传码(没错为0)
export
自定义变量转成环境变量,子进程仅会继承父进程的的环境变量,而不会继承自定义变量
declare
反过来
export PYTHONPATH=~/Documents/zsProjects/zsNao/zsROSNaoqi/pynaoqi-python2.7-2.1.4.13-linux64:$PYTHONPATH
添加环境变量
echo 'export PYTHONPATH=~/Documents/zsProjects/zsNao/zsROSNaoqi/pynaoqi-python2.7-2.1.4.13-linux64:$PYTHONPATH' >> ~/.bashrc
永久添加环境变量
更新
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get autoremove
sudo apt-get autoclean
安装
sudo aptitude install name
更改计算机名
sudo gedit /etc/hostname
sudo gedit /etc/hosts
两个地方的名字需一致
网络远程登陆工具
ssh
查看网速
nload
启动器上应用程序图标为灰色问号?
cd ~/.local/share/applications/
gedit ${某一个桌面快捷方式文件}
${ICON}变量进行设置
处理包冲突问题技巧
aptitude
Getting Help:
- When asking for help on Askubuntu or any other help forum, you should include the output of the following commands in your question:
sudo apt-get install package-name
Output of actual error.
cat /etc/apt/sources.list
This will show your sources.list
cat /etc/apt/sources.list.d/*
This will show the list of PPAs (If any).
Umet dependencies——软件安装包冲突时的解决思路
- 备份APT源数据文件
APT is a package management system for Debian and other Linux distributions based on it, such as Ubuntu. For the most part, APT is easy to use for installing, removing, and updating packages. In rare instances, often when you are mixing in third-party dependencies, there is a chance that apt-get may end up giving you an error telling you that a package installation could not be completed.
It is always a good idea to back up configuration files like /etc/apt/sources.list, so you can revert the changes if needed. - 版本号不一致,有一个版本已经安装,但是你要安装另一个版本
If the error shows something like this:
: Depends: (= version) but this-version is to be installed
Then make sure that the restricted and universe repositories are enabled. Hit Alt+F2, type software-properties-gtk and hit Enter.
Under Ubuntu Software tab, enable all the repositories.
sudo apt-get clean
sudo apt-get autoclean
One possible cause of unmet dependencies could be corrupted package database, and/or some packages weren’t installed properly. To fix this problem, hit Alt+Ctrl+T to open terminal and try to run one of the following commands:
apt-get clean clears out the local repository of retrieved package files (the .deb files). It removes everything but the lock file from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/. apt-get autoclean clears out the local repository of retrieved package files, but unlike apt-get clean, it only removes package files that can no longer be downloaded, and are largely useless.
autoclean基本没什么用,clean有用一些
sudo apt-get -f install
One of the most basic fixes to resolve dependencies problems is to run:
The -f here stands for “fix broken”. Apt will attempt to correct broken dependencies. If you manually installed a package that had unmet dependencies, apt-get will install those dependencies, if possible, otherwise it may simply remove the package that you installed in order to resolve the problem.
Then run:
sudo dpkg --configure -a
Then run this again:
sudo apt-get -f install
If the output is:
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
That means it failed.
sudo apt-get -u dist-upgrade
Next solution is to run:
sudo apt-get -o Debug::pkgProblemResolver=yes dist-upgrade
If it shows any held packages, it is best to eliminate them. Packages are held because of dependency conflicts that apt cannot resolve. Try this command to find and repair the conflicts:
If it cannot fix the conflicts, it will exit with:
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.
sudo apt-get remove --dry-run package-name
Delete the held packages one by one, running dist-upgrade each time, until there are no more held packages. Then reinstall any needed packages. Be sure to use the --dry-runoption, so that you are fully informed of consequences:
Since removing the package you are trying to install may not be ideal, you might also try finding a repository that has the packages you need to satisfy the dependencies.
使用命令计算处有错误的包集,尝试删除之,注意所有删除的细节,免得造成不好后果。
Finally, if all else fails, you can attempt to satisfy the dependencies yourself, either by finding and installing the necessary packages, or by installing them from source and then creating “deb” packages for them.
如果所有的都失败了,没办法了,手动找吧。删除或者安装
关于PPAs(Personal Package Archive)
- PPAs (Personal Package Archive) are repositories hosted on Launchpad. You can use PPAs to install or upgrade packages that are not available in the official Ubuntu repositories.
- One of the most common causes of unmet dependencies are PPAs, specially when used to upgrade the existing package in Ubuntu repositories. To solve the problem you have three options, disable, purge (revert back to original package in Ubuntu repositories) or remove PPA.
Disable:
- Disabling a PPA means no more updates for the packages installed from that PPA. To disable a PPA: Open Software Center > Edit > Software Sources Or,
- Hit Alt+F2 and run software-properties-gtk.
Click on Other Software tab, you'll see that each PPA have two lines here, one for the compiled packages and one for the source, Uncheck both lines to disable a PPA. Here you can also add and remove PPAs.
Purge:
Purging a PPA means, downgrading the packages in the selected PPA to the version in the official Ubuntu repositories and disabling that PPA. PPA Purge does exactly that. To install PPA Purge run the following command:
sudo apt-get install ppa-purge
- But, Considering the question apt is broken so the above command will fail. So use this command
mkdir ppa-purge && cd ppa-purge && wget http://mirror.pnl.gov/ubuntu/pool/universe/p/ppa-purge/ppa-purge_0.2.8+bzr56_all.deb && wget http://mirror.pnl.gov/ubuntu//pool/main/a/aptitude/aptitude_0.6.6-1ubuntu1_i386.deb && sudo dpkg -i ./*.deb
- To use PPA Purge:
sudo ppa-purge ppa:someppa/ppa
- If 'ppa-purge' command fails for some reason, you can't run 'ppa-purge' again unless you re-enable the PPA (To enable the PPA follow the same steps as disabling a PPA and Check the both lines of a particular PPA to enable it).
Note: PPA Purge doesn't remove PPAs (may be in future), So you'll have to manually remove the PPA.
Remove:
- If the package installed from a PPA doesn't exist in official Ubuntu repositories then using PPA Purge is not recommended, because there's nothing to be downgraded and PPA Purge wouldn't delete it either. To remove a PPA and installed packages run the following commands: (Ignore the first command if you don't want to remove the installed packages)
sudo apt-get autoremove --purge package-name
sudo add-apt-repository --remove ppa:someppa/ppa
sudo apt-get autoclean
- Alternatively you can use Y PPA Manager to disable/remove/purge PPA's (Details at the end of answer).
Preventive Measures:
- So how can we avoid this from happening in the first place?
Keep Ubuntu Up to date. Ubuntu automatically notifies when updates are available, you can also check for available updates by clicking on Session Indicator in Unity panel:
Or, Hit Alt+Ctrl+T to open terminal and run following commands:
sudo apt-get update
sudo apt-get upgrade
Update: Synchronizes your list of available packages with the servers in source repositories. Upgrade: Downloads & installs any newer versions of your installed packages.
- 常更新!
If you decide to add other repositories to sources.list, make sure that the repository is meant to work (and known to work) with Ubuntu. Repositories that are not designed to work with your version of Ubuntu can introduce inconsistencies in your system and might force you to re-install. Also, make sure that you really need to add external repositories as the software package(s) you are looking for may already have been introduced into the official repositories!
Remove duplicate PPAs. Y PPA Manager (installation guide at the end of answer) can easily scan and remove duplicate PPAs.
Hit Alt+F2 and run y-ppa-manager to open Y PPA Manager.Once open, double click or hit Enter on Advanced.In resulting window select Scan and remove duplicate PPAs and click OK.
双硬盘同引导双系统
- 先认真把《鸟叔》看懂!
- 基本条件,SSD(sd0)装windows,同时HDD(sd1)作为数据盘;计划把Ubuntu安装在HDD的一个分区中,分/swap,/boot,/,/home 四个分区;但是第一次安装,建议就在HDD中的F盘,主分区中安装吧,F盘是HDD的一个分区
重新分区的问题
- 恢复分区怎么处理?(恢复分区是主分区,而且有三个,删除哪些?要弄懂)
- 安装Ubuntu要不要分多个区?(不打算分swap)
- / 和/home最好分别mount到ssd和hard drive上!
- 打算这样:SSD上/分18G;HDD上F盘100G分出两个分区用来装/usr和/home
- 考虑到/var也很费内存,则考虑在SSD上只安装/boot,F盘分两个装/和/home
这样重装系统时候只需格式化/boot和/分区,继续挂载/home分区
现在这样,在SSD上的512M地方放/boot,在F盘的扩展分区分两个区,bootloader安装在SSD上
装系统实践
- 备份文件;制作安装U盘;删除卷;检查BIOS;
- 实测:当前windows还是在HDD的启动扇区进去的,不知道为什么,所以现在的方式是在F盘中分/和/home,bootloader安装在HDD中,注意如果有选择HDD的哪一个分区的话,马上取消,查答案。(结果是,既可以选在硬盘的第一个扇区,也可以选择硬盘的某一个分区的扇区)
- 关于device for boot loader installation
- 这个bootloader 其实是grub,即选择grub的安装位置
- device for boot loader installation的选择(grub的安装位置),如果选择整个硬盘,则开机启动时win会被ubuntu管理启动(用grub引导 windows),这样卸载ubuntu后,win也会将启动丢失,引起系统进不去的问题(当然可以修复);如果device for boot loader installation选择ubuntu的/boot所在的分区后,下次启动会默认进入win,这时只要在win下用freebcd添加个ubuntu的引导就行了。
- 装完系统后请关闭windows的快速启动,不然关机后再次启动直接进Linux无法挂载windows磁盘,因为windows并未真正关闭
- 当然,如果不关闭快速启动,可以每次开机默认进入windows,然后想使用Linux时按重新启动即可。
- 设置Grub,配置文件,设置默认启动项和等待秒数
缺少库文件
- 原因一般有两个, 一个是操作系统里确实没有包含该共享库(lib.so.文件)或者共享库版本不对, 遇到这种情况那就去网上下载并安装上即可.
- 另外一个原因就是已经安装了该共享库, 但执行需要调用该共享库的程序的时候, 程序按照默认共享库路径找不到该共享库文件.
- 共享库路径设置问题, 如下:
- 如果共享库文件安装到了/lib或/usr/lib目录下, 那么需执行一下ldconfig命令
ldconfig命令的用途, 主要是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf内所列的目录下, 搜索出可共享的动态链接库(格式如lib.so), 进而创建出动态装入程序(ld.so)所需的连接和缓存文件. 缓存文件默认为/etc/ld.so.cache, 此文件保存已排好序的动态链接库名字列表. - 如果共享库文件安装到了/usr/local/lib(很多开源的共享库都会安装到该目录下)或其它"非/lib或/usr/lib"目录下, 那么在执行ldconfig命令前, 还要把新共享库目录加入到共享库配置文件/etc/ld.so.conf中, 如下:
# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig
- 如果共享库文件安装到了其它"非/lib或/usr/lib" 目录下, 但是又不想在/etc/ld.so.conf中加路径(或者是没有权限加路径). 那可以export一个全局变量LD_LIBRARY_PATH, 然后运行程序的时候就会去这个目录中找共享库.
- LD_LIBRARY_PATH的意思是告诉loader在哪些目录中可以找到共享库. 可以设置多个搜索目录, 这些目录之间用冒号分隔开. 比如安装了一个mysql到/usr/local/mysql目录下, 其中有一大堆库文件在/usr/local/mysql/lib下面, 则可以在.bashrc或.bash_profile或shell里加入以下语句即可:
export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH
一般来讲这只是一种临时的解决方案, 在没有权限或临时需要的时候使用.