Jex’s Note

Ubuntu

查 ubuntu 版本

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 13.10
Release:        13.10
Codename:       saucy

升級 Linux kernel

查看目前版本

確切版號
$ uname -r
4.8.3-x86_64-linode76

$ uname -a
Linux 139-162-12-42 4.8.3-x86_64-linode76 #1 SMP Thu Oct 20 19:05:39 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux

尋找要的 Kernel image

sudo apt-get update
sudo apt-cache search linux-image

    linux-image-3.19.0-15-generic - Linux kernel image for version 3.19.0 on 64 bit x86 SMP
    linux-image-3.19.0-15-lowlatency - Linux kernel image for version 3.19.0 on 64 bit x86 SMP
    (...略)

apt-get install linux-image-xxx

重開後移除原本的版本

reboot
sudo apt-get remove linux-image-ooo

升級 Linux 小版

sudo apt-get update
sudo apt-get dist-upgrade

更換mirror, 官方認可Mirror名單

[1] 修改Mirror源檔

sudo vim /etc/apt/sources.list

[2] 取代成 NCHC, Taiwan (National Center for High-performance Computing, Taiwan)

%s/http:\/\/tw.archive.ubuntu.com\/ubuntu\//http:\/\/free.nchc.org.tw\/ubuntu\//g

apt 指令

  • apt-cache search 'openjdk' : 尋找套件
  • apt-get update : 更新套件列表
  • apt-get upgrade : 更新已安裝套件列表
  • apt-get dist-upgrade : 更新已安裝套件(含相依)列表
  • apt-get install phpmyadmin : 安裝套件 , 例如 : phpmyadmin
  • apt-get remove phpmyadmin : 移除套件 , 例如 : phpmyadmin
  • apt-get autoremove phpmyadmin : 移除(含相依)套件 , 例如 phpmyadmin
  • apt-get -purge phpmyadmin : 移除套件及設定檔 , 例如 phpmyadmin
  • apt-get clean : 清除暫存檔

install 時找不到某個套件

apt-get install software-properties-common
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
sudo add-apt-repository "deb http://ftp.osuosl.org/pub/mariadb/repo/5.5/ubuntu $(lsb_release -c -s) main"
sudo apt-get update
sudo apt-get install mariadb-server mariadb-client

dpkg 指令

指令安裝.deb

sudo dpkg -i 檔案名稱.deb   //apt-get 是安裝套件(包含相依套件) , dpkg是個別檔案

移除套件.deb

sudo dpkg -r 檔案名稱.deb

查詢是否安裝某個套件 (例如git)

dpkg --get-selections | grep git

查詢已安裝套件的版本(例如php)

dpkg -l | grep php

查看套件版本等資訊

dpkg -s xfsprogs

檢查套件是否安裝

dpkg -s libapache2-mod-php5 | grep installed
Status: install ok installed
  • -s|–status … Display package status details.
  • -S|–search … Find package(s) owning file(s).

更新單一套件

sudo apt-get install packageName

This will upgrade the package even if is already installed

or

sudo apt-get --only-upgrade install packageName

重新安裝套件

user@hostname:~$ sudo apt-get purge mysql-server-5.5 mysql-client-5.5
user@hostname:~$ sudo apt-get autoremove
user@hostname:~$ sudo apt-get install mysql-server-5.6 mysql-client-5.6

sudo add-apt-repository : command not found

execute :

sudo apt-get update
sudo apt-get install python-software-properties

or

sudo apt-get install software-properties-common

apt-get purge 與 remote 的差別

remove : remove - Packages installed are removed (Does NOT include configuration files)

purge : purge - Purge is identical to remove except that packages are removed and purged. Purge meaning that any configuration files are deleted too.

修改 hostname

[1] 修改 /etc/hostname, ex: ec2

[2] 修改 /etc/hosts, 加上 127.0.1.1 ec2

[3] sudo hostname -F /etc/hostname

-F, –file : read host name or NIS domain name from given file

Set Time zone

查看目前的 timezone

$ cat /etc/timezone
Etc/UTC

設定 time zone

sudo tzselect

執行 command, 或加在 .bashrc 裡

TZ='Asia/Taipei'; export TZ

重啟 time zone

sudo dpkg-reconfigure tzdata

設定完成後立即生效

cat /etc/timezone
Asia/Taipei

(Optional) 重啟 crontab

sudo service cron restart

Set Locale

查看目前 default

$ cat /etc/default/locale
LANG="en_US.UTF-8"

查看目前有的

$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE=UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

perl warning

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").

你用 SSH 連到主機而主機的 SSH 設定

/etc/ssh/sshd_config :

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

你的 OS 不認識 en_US.UTF-8

解決方法1 : 使用以下方式連到 server

LC_ALL=C ssh your_server

解決方法2 : 加在 .bashrc

export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_TYPE=en_US.UTF-8

內建自動啟動的套件

取消自動啟動

sudo update-rc.d nginx disable

移除

sudo update-rc.d -f apache2 remove

Comments