2015年10月9日 星期五

Ubuntu 與安裝軟體有關的指令

要在 Ubuntu 作業系統安裝軟體的基本步驟如下:
  1. 將某個軟體的網站加到軟體來源列表裡(/etc/apt/sources.list)
  2. 更新系統的軟體資料庫列表
  3. 安裝該軟體套件
軟體來源列表是一個文字檔案(/etc/apt/sources.list),我們可以透過下面指令來查看該檔案的內容。
   
   sudo gedit /etc/apt/sources.list

下面為該檔案的部分內容,# 號開頭的為檔案註解可以不理會它;deb 開頭表示是 debian 套件包 (Ubuntu 的底層核心是 debian);接下來可以看到一個網址列,這是告訴系統要到哪個網站裡去下載這個套件包;接下來可以看到 precise ,這個是代表版號,每個版本都有不同的代號,代號可以查看這裡。最後的 universe 代表是社群維護的套件庫。Ubuntu 有四個內定的套件庫如下表:
  
## Major bug fix updates produced after the final release of the
## distribution.
deb http://us.archive.ubuntu.com/ubuntu/ precise-updates main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ precise-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://us.archive.ubuntu.com/ubuntu/ precise universe 

Ubuntu 四個內定的套件庫如下表:
名稱 套件庫說明
Main 主要套件庫,由 Ubuntu 所支援維護。
Restricted 私有版權的硬體驅動程式。
Universe 由社群所維護支援的套件庫。
Multiverse 非自由的軟體套件庫。這裡指的非自由並非是不合法的軟體,而是這些軟體並不符合自由軟體授權模式。

在 Ubuntu 中所謂加入第三方軟體庫,只是很簡單的打開 /etc/apt/sources.list 這個文字檔,然後把官網提供的網址附加到最後一行,儲存起來就搞定了。但是由於手動更動這個文字檔有相當大的風險存在,因此 9.10 版本之後有了一個更好用的指令:
   
   add-apt-repository

這個指令顧名思義的就是加入第三方來源庫的指令,主要避免使用 gedit 文字處理器來處理一行行的網址列,同時配合近來流行的 PPA (Personal Pacakge Archives),讓你可以很方便的下載各式各樣的應用軟體。
接下來我們來實際安裝 Ubuntu-tweak 軟體套件,基本上你沒有加入該套件到軟體來源列表,當透過下面指令安裝程式時會出現 E: Unable to locate package ubuntu-tweak 的訊息:
   
josh:~$ sudo apt-get install ubuntu-tweak
[sudo] password for josh: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package ubuntu-tweak

如我們前面所提要在 Ubuntu 作業系統安裝軟體的基本三步驟 1.加入第三方來源、2.更新軟體資料庫、3.安裝軟體:
 
sudo add-apt-repository ppa:tualatrix/ppa
sudo apt-get update
sudo apt-get install ubuntu-tweak

apt-get 的全名是 Advanced Package Tool-get,專業的套件包工具。update 是命令系統進行更新套件庫的動作。install 代表安裝,安裝甚麼呢,就是後面提供的套件名稱。

當我想知道套件庫裡有沒有一個套件叫做 scibus 的文書排版軟體,可以透過下面指令來查詢:
   
   apt-cache search scribus

上面的指令會在 apt 套件資料庫的快取裡,查詢名稱內容裡有 scribus 的套件並顯示出來。
安裝 scibus 套件:
   
   sudo apt-get install scribus

把它移除,但是保留設定檔:
   
   sudo apt-get remove scribus

把它移除,連設定檔也一併清除:
 
   sudo apt-get purge scribus
或  
   sudo apt-get remove --purge scribus

手動更新系統:
 
   sudo apt-get update
   sudo apt-get upgrade

注意:你可從網站下載附檔名為 deb 的安裝檔案,透過 deb 格式安裝的軟體並不會自動更新,也就是說假設安裝了 1.0 版本,但是現在有 1.1 版了,必須自行再次下載安裝;同時安裝 deb 格式時,有時候會遇到套件相依不足的問題,因此建議,若非必要,不要直接使用 deb 格式的檔案來進行應用程式安裝,而應該使用軟體中心或其他軟體來源庫的方式安裝。
[參考連結]

2015年10月8日 星期四

在 Ubuntu 12.04 LTS 上安裝 nautilus-gksu

Ubuntu 12.04 版本後 nautilus-gksu 套件,已經從 Ubuntu repositories 中移除了,要安裝必須把它重新加入,請參考下面方式加入及安裝 nautilus-gksu。

sudo apt-add-repository ppa:upubuntu-com/ppa
sudo apt-get update
sudo apt-get install nautilus-gksu

用下面指令或是登出系統在登入以重新啟動 nautilus,點選目錄右鍵後就可以在選單中看到 "Open as administrator" (以系統管理員身分開啟)選項。

nautilus -q

[Reference]

2015年10月4日 星期日

How to add/remove PPAs?

Add:
sudo add-apt-repository ppa:ubuntu-sdk-team/ppa
sudo apt-get update

Remove-1:
sudo add-apt-repository --remove ppa:ubuntu-sdk-team/ppa
sudo apt-get update

Remove-2:
sudo add-apt-repository -r ppa:ubuntu-sdk-team/ppa
sudo apt-get update

Remove-3 using ppa-purge tool:
sudo apt-get install ppa-purge
sudo ppa-purge ppa:ubuntu-sdk-team/ppa

Remove-4:
ls -al /etc/apt/sources.list.d
sudo rm -i /etc/apt/sources.list.d/ubuntu-sdk-team-ppa-precise.list

[References]

Virtualbox kernel service is not running

最近更新了 VirtualBox 4.3.30 版本後,然後再 Client OS Ubuntu 12.04 LTS 中重新安裝 Guest Additions 後;重新啟動 Ubuntu 時卻發現登入的時候會出現 "Virtualbox kernel service is not running" 的訊息,如下畫面所示:



最後在 "VirtualBox Ubuntu 14.04 - vboxclient the virtualbox kernel service is not running" 找到了解法,透過下面的方式重新安裝 Guest Additions 也無法解決問題。
linux:/media/VBOXADDITIONS_4.3.30_101610$ sudo ./VBoxLinuxAdditions.run

直到執行下面的命令後:
linux:~$ sudo /etc/init.d/vboxadd setup

出現下面的錯誤訊息:


之後檢查訊息所提供的提示去檢查 /var/log/vboxadd-install.log 檔案,其訊息如下圖所示:



由上圖所示可以發現無法編譯成功,所以回想之前我有將 gcc 升級到 gcc5,且將其設定為預設的編譯器版本,因此將 gcc 版本設定回原本的 4.6.4 版本後,重新執行 vboxadd setup 就可以順利編譯成功,重新開機後也沒出現 "Virtualbox kernel service is not running" 的警告訊息囉。

2015年9月23日 星期三

查詢所安裝的 Ubuntu 版本訊息

1.lsb_release -a 查詢版本資訊
linux:~/Downloads$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.4 LTS
Release: 12.04
Codename: precise

2.cat /etc/*release
linux:~/Downloads$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.4 LTS"
NAME="Ubuntu"
VERSION="12.04.4 LTS, Precise Pangolin"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu precise (12.04.4 LTS)"
VERSION_ID="12.04"

3. cat /etc/issue 或 cat /etc/issue.net
linux:~/Downloads$ cat /etc/issue
Ubuntu 12.04.4 LTS \n \l

linux:~/Downloads$ cat /etc/issue.net
Ubuntu 12.04.4 LTS

4. cat /proc/version 可以得知核心版本、何時編譯且用哪一版的 gcc 所編譯
linux:~/Downloads$ cat /proc/version
Linux version 3.8.0-42-generic (buildd@allspice) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #62~precise1-Ubuntu SMP Wed Jun 4 22:04:18 UTC 2014

5. uname -r 得知核心版本資訊
linux:~/Downloads$ uname -r
3.8.0-42-generic


6. uname -i 或 uname -m 取得目前的架構是 64 或 32 位元
linux:~/Downloads$ uname -i
x86_64
linux:~/Downloads$ uname -m
x86_64

7.file /sbin/init 取得目前的架構是 64 或 32 位元
linux:~/Downloads$ file /sbin/init
/sbin/init: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x7aa29ded613e503fb09fb75d94026f3256f01e7a, stripped

8. dpkg --print-architecture 取得目前的架構是 64 或 32 位元
linux:~/Downloads$ dpkg --print-architecture
amd64

9. getconf LONG_BIT 取得目前的架構是 64 或 32 位元
linux:~/Downloads$ getconf LONG_BIT
64

10. uname -a 得知核心版本資訊以及架構 i386 為 32 位元; x86_64 為 64 位元
linux:~/Downloads$ uname -a
Linux linux 3.8.0-42-generic #62~precise1-Ubuntu SMP Wed Jun 4 22:04:18 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

11. cat /proc/cpuinfo 取的 CPU 資訊
linux:~/Downloads$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model  : 42
model name : Intel(R) Pentium(R) CPU G840 @ 2.80GHz
stepping : 7
cpu MHz  : 2792.759
cache size : 6144 KB
fpu  : yes
fpu_exception : yes
cpuid level : 5
wp  : yes
flags  : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc rep_good nopl pni monitor ssse3 lahf_lm
bogomips : 5585.51
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:




[參考資料]

如何升級升級/降級 Ubuntu 12.04 的 Firefox 以及安裝 Chrome

你可以透過 apt-cache show firefox | grep Version 指令來查詢目前 Ubuntu 所提供的套件版本資訊。在執行前請先執行 sudo apt-get update 指令以確保得到是最新資訊。執行後應該會顯示如下的訊息:
linux$ apt-cache show firefox | grep Version
Version: 41.0+build3-0ubuntu0.12.04.1
Version: 11.0+build1-0ubuntu4

更新 firefox 只需要下達如下指令即可,如果有新的版本可用便會開始安裝新版本。
sudo apt-get update
sudo apt-get install firefox

更新完後新版本如果有問題,如何將 firefox 安裝成以前的版本呢?

1. 到 https://launchpad.net/ubuntu/precise/+source/firefox 下載你要的版本。
這邊我們下載 firefox version 31.0 64 bit https://launchpad.net/~ubuntu-mozilla-security/+archive/ubuntu/ppa/+build/6185582/+files/firefox_31.0%2Bbuild1-0ubuntu0.12.04.1_amd64.deb

2. 解除安裝 firefox
sudo apt-get purge firefox


3. 安裝在第一步驟所下載的 firefox 套件。
sudo dpkg -i firefox_31.0+build1-0ubuntu0.12.04.1_amd64.deb

萬一在你下在 firefox 舊套件前你就把你的 firefox 移除的話,你可以透過 wget 來下載套件,然後在執行安裝即可。
wget https://launchpad.net/~ubuntu-mozilla-security/+archive/ubuntu/ppa/+build/6185582/+files/firefox_31.0%2Bbuild1-0ubuntu0.12.04.1_amd64.deb

如何安裝 Chrome,到 https://www.google.com.tw/chrome/browser/desktop/ 網頁按"下載"按鈕後;選擇你的 Linux 平台後按 "接受並安裝" 按鈕後;點選 "Open with" 然後選擇 "Ubuntu Software center" 如下圖所示:

等Ubuntu Software center開啟後按 install 按鈕即可以安裝 Chrome;如下圖所示:

[參考鏈結]

2015年9月21日 星期一

如何更新 Ubuntu 12.04 上的 gcc 與 g++

當安裝好 Ubuntu 12.04 其預設安裝的 gcc 與 g++ 版本為 4.6 你可以透過 g++ --version 來查詢你系統上的版本:
linux:~$ g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

更新步驟可依序執行下列指令即可:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-5 g++-5

為了讓 update-alternatives 知道我們系統上有 2 套 gcc 與 g++ 編譯器,我們必須為每套 gcc 與 g++ 建立安裝紀錄;然後再透過 config 來設定系統所要載入的版本,設定方法如下:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 40 --slave /usr/bin/g++ g++ /usr/bin/g++-5
sudo update-alternatives --config gcc

當你執行 sudo update-alternatives --config gcc 會看到如下的選單畫面,而在此畫面我選擇了 2:
linux:~$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gcc-4.6   60        auto mode
  1            /usr/bin/gcc-4.6   60        manual mode
  2            /usr/bin/gcc-5     40        manual mode

Press enter to keep the current choice[*], or type selection number: 2       
update-alternatives: using /usr/bin/gcc-5 to provide /usr/bin/gcc (gcc) in manual mode.

完成上面設定後執行 g++ --version 你應該可以看到如下面的訊息:
linux:~$ g++ --version
g++ (Ubuntu 5.1.0-0ubuntu11~12.04.2) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


[參考連結]