前言
- 纯粹笔记,以防忘记
目录
- 记录
记录
在live cd 下为某磁盘安装grub
- 从live cd 进入ubuntu
1 | sudo su |
这是某磁盘ubuntu 启动分区
1 | grub-install --root-directory=/mnt /dev/sdc |
重启电脑进入该磁盘,会报错,但可以正常进入ubuntu,然后在该系统中更新即可!
1 | sudo update-grub |
挂载
1 | sudo mount -o loop -t hfsplus imagefile.img /mnt |
更改主显示器
1 | xrandr |
查看显示器详细信息
1 | xrandr --output DFP5 --auto --primary |
查看设备
1 | ls /dev/ | grep video |
grub 图形化编辑
1 | sudo add-apt-repository ppa:danielrichter2007/grub-customizer |
查找 package
1 | dpkg -l | grep xmind |
查询链接库依赖项
1 | .../platforms$ ldd libqxcb.so |
删除文件夹
1 | sudo rm -rf ./Robai/ |
查找包
1 | apt-cache search pcl |
卸载包
1 | sudo dpkg -r pcl |
卸载软件
1 | sudo apt-get remove ros-indigo-moveit-full |
grub
1 | sudo cp /etc/default/grub /etc/default/grub.bak |
GRUB_DEFAULT=
GRUB_TIMEOUT=5
1 | sudo update-grub |
修改hosts文件
1 | sudo gedit /etc/hosts |
127.0.1.1 zsUbuntu
Choose server
- Choose the ubuntu server sjtu.edu.cn
su 命令失败
- 试试sudo su进入root模式
环境变量
1 | env |
查看环境变量
1 | set |
查看所有变量(环境变量+自定义变量)
1 | echo ${PATH} |
添加路径至PATH环境变量
路径可以不加单引号
1 | echo $$ |
当前线程的PID号码
1 | echo $? |
上个命令的回传码(没错为0)
1 | export |
自定义变量转成环境变量,子进程仅会继承父进程的的环境变量,而不会继承自定义变量
declare反过来
1 | export PYTHONPATH=~/Documents/zsProjects/zsNao/zsROSNaoqi/pynaoqi-python2.7-2.1.4.13-linux64:$PYTHONPATH |
添加环境变量
1 | echo 'export PYTHONPATH=~/Documents/zsProjects/zsNao/zsROSNaoqi/pynaoqi-python2.7-2.1.4.13-linux64:$PYTHONPATH' >> ~/.bashrc |
永久添加环境变量
更新
1 | sudo apt-get update |
安装
1 | sudo aptitude install name |
更改计算机名
1 | sudo gedit /etc/hostname |
两个地方的名字需一致
网络远程登陆工具
ssh
查看网速
nload
启动器上应用程序图标为灰色问号?
1 | cd ~/.local/share/applications/ |
处理包冲突问题技巧
1 | 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:
1 | sudo apt-get install package-name |
Output of actual error.
1 | cat /etc/apt/sources.list |
This will show your sources.list
1 | 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:
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.
1 | sudo apt-get clean |
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有用一些
1 | 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:
1 | sudo dpkg --configure -a |
Then run this again:
1 | 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.
1 | sudo apt-get -u dist-upgrade |
Next solution is to run:
1 | 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.
1 | 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:
1 | sudo apt-get install ppa-purge |
- But, Considering the question apt is broken so the above command will fail. So use this command
1 | 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:
1 | 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)
1 | sudo apt-get autoremove --purge package-name |
- 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:
1 | sudo apt-get update |
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!
- 添加源时应谨慎,一定要添加么?这个软件适合当前Ubuntu版本么?这个外部源是否已经存在于官方源中了呢?
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中, 如下:
1 | # cat /etc/ld.so.conf |
- 如果共享库文件安装到了其它”非/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
一般来讲这只是一种临时的解决方案, 在没有权限或临时需要的时候使用.