0% found this document useful (0 votes)
29 views38 pages

02 Installing Applications

The document provides a comprehensive guide on installing applications in FreeBSD, detailing the use of package management systems like 'pkg' and the ports collection. It covers essential commands for installing, upgrading, and managing software, as well as security considerations and methods for uninstalling applications. Additionally, it explains the importance of user permissions and the 'sudo' command for executing administrative tasks safely.

Uploaded by

洪邦邦
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views38 pages

02 Installing Applications

The document provides a comprehensive guide on installing applications in FreeBSD, detailing the use of package management systems like 'pkg' and the ports collection. It covers essential commands for installing, upgrading, and managing software, as well as security considerations and methods for uninstalling applications. Additionally, it explains the importance of user permissions and the 'sudo' command for executing administrative tasks safely.

Uploaded by

洪邦邦
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Installing Applications in

FreeBSD
tsaimh(2022-2023, CC BY-SA)
lctseng (2019-2021, CC BY-SA)
? (1996-2018)
國立陽明交通⼤學資⼯系資訊中⼼
Information Technology Center, Department of Computer Science, NYCU
Handbook and Manual pages
● Complete guide and be found at
○ https://www.freebsd.org/doc/handbook/ports.html
○ https://www.freebsd.org/doc/zh_TW/books/handbook/ports.html
○ ports(7)
○ pkg(7), pkg(8)

2
Before we start (1)
● Permission issue
○ root: the superuser
■ In Unix-like system, root is the conventional name of the user who has
all rights or permissions (to all files and programs) in all modes
(single- or multi-user)
● Don't execute any command as root directly
○ It's DANGEROUS
● However sometimes you still need to be root to do something
○ Install software
○ Manage system settings
○ Create/modify/delete users
3
Before we start (2)
● Become root
○ Console login with root $ whoami
tsaimh
○ By default, you cannot login as root via SSH
$ su -
● Change current user
Password:
○ Don't need to login with console
○ Use command "su -", and then type root's password $ whoami
■ Only user in "wheel" group can use "su - " to root
change to root
○ To see which account you are using, use "whoami"

4
Before we start (3)
● As mentioned before, don't run as root directly
● Can we execute with root's credential only for some specific
commands?
○ Like 'Run as administrator' in Windows
○ Is there similar commands in Unix-like system/FreeBSD?

5
Before we start (4)
● Run commands with other user's permission
● "sudo" command
○ Only simplest explanation here for basic usage
○ "sudo" syntax and other details will be explained in later chapters
○ Here only tell you how to simply enable 'sudo'
● How to enable sudo?
○ "sudo" is not a command in the base, needs to be installed manually

6
Enable "sudo" (1)
● Install the package
○ Check Internet connection
■ $ ping -c4 8.8.8.8
○ Become root
■ $ su -
○ Install the package of sudo
■ $ pkg install sudo
● This will install 'sudo' from Internet
● Type ‘Y’ ( means yes) when it asks for confirmation

7
Enable "sudo" (2)
● Allowing your user to execute "sudo"
○ Switch to root first
○ If you are not familiar with the default editor 'vi', type the following
command to change your editor for this time (skip this step
otherwise)
$ setenv EDITOR ee
■ Will explain this in later chapters
■ This will allow you using a notepad-like editor

8
Before we start – Enable "sudo" (3)
● Allowing your user to execute "sudo"
○ Type "visudo" to edit the sudoer file
■ Specify who can use "sudo"

##
## User privilege specification
##
root ALL=(ALL) ALL
tsaimh ALL=(ALL) ALL

○ Save the file and exit, back to normal user


■ Use "logout" command or press Ctrl+D
9
Before we start – Using "sudo"
● Now, you can prepend "sudo" before commands to run them as root
○ But please think carefully before you hit enter
● Execute commands with "sudo"
○ sudo whoami
■ You have root's credential
○ sudo pkg install vim
■ Install software without becoming root directly
○ You need to re-type your password
■ Don't need to re-type within 5 minutes

10
Install software: Overview (1)
● Package (Pre-built binary programs)
○ Like installers (.msi) in Windows
○ "package" (.txz) on FreeBSD
○ rpm on RedHat Linux, deb on Debian Linux
● Package Manager
○ install/remove/upgrade packages
○ Other Unix-like systems
■ rpm, yum, dpkg, apt, dnf, pacman …
○ FreeBSD
■ pkg

11
Install software: Overview (2)
● Install from source
○ Managed source collection
■ FreeBSD Ports
■ With dependency checking and FreeBSD specified patches
○ Others
■ Download source tarball (.tar.gz) from websites
■ Checkout from VCS (git/svn)
■ No dependency checking

12
Install software: Comparison (1)
Dependency
Method Description
Checking
Pre-built ports, contains pre-compiled copies of all the commands
Packages for the software with default settings, as well as any configuration Yes
files or documentation.
A collection of files designed to automate the process of compiling
Ports an software from source code and additional patches (a set of Yes
Makefile, patches, description files, …)
Tarball fetch it, configure the installation options, and compile it by
No
VCS yourself.

13
Install software: Comparison (2)
Method Benefits
● Packages do not require any additional compilation
Packages ● Benefit for slow machines
● Optimization
○ You can tweak the compilation options to generate code that is
specific to a different processor
Ports
● Customization
○ Some software have compilation time options relating to what they
can and cannot do
● Some software cannot be found in ports collection
Tarball ○ Newly created projects, latest versions, ...
VCS ● Some latest versions of software may have new configurations that do
not exist in ports (cannot configure it through the ports easily)
14
Package System (1)
● pkg
○ New generation of FreeBSD package system
● Install new software
○ Fetch packages from a repository
○ Need root permission (sudo)
○ Automatically update the database
■ By default invoking either of pkg install or pkg upgrade will cause
repository catalogues to be updated automatically
○ Perform dependency check
■ Will install software that required by new software

15
Package System (2)
● Install new software
○ pkg install <names of packages…>
■ pkg install vim-console tmux
● Upgrade currently installed software
○ pkg upgrade <names of packages…>
■ pkg upgrade vim-console
○ pkg upgrade
■ Upgrade all installed software
○ This will also update the database

16
Package System (3)
● Update packages database only
○ pkg update
● Delete a package
○ pkg delete <names of packages>
● Search
○ pkg search <keyword>
○ Search package repository catalogues

17
Package System (4)
● Show information about installed packages
○ pkg info
■ Show all installed packages
■ Use "grep" to find specific packages
● pkg info | grep vim
○ pkg info <name of package>
■ Show detailed information
■ pkg info vim-console

18
Package System (5)
● Show version of installed packages
○ pkg version
■ pkg version -v

$ pkg version -v
bash-4.3.46_1 < needs updating (remote has 4.4.12_2)
bind99-9.9.9P8_1 < needs updating (remote has 9.9.10P3)
ca_root_nss-3.32 = up-to-date with remote

19
Port System
● We should…
○ Obtain the ports collection
■ List of ports available to be installed into system
○ Find the application
○ Change to the directory for the port
● Ports will
○ Fetch the source tarball
○ Ask for configuration friendly
○ Compile the source code to a package
○ Install the application via the just built package
● Deinstall process
20
Obtaining the Ports Collection (1/3)
● portsnap(8)
○ Fetch and update your ports tree
○ fetch, extract, update, cron
○ sudo portsnap fetch extract update
○ https://www.freebsd.org/doc/en_US.ISO8859-
1/books/handbook/ports-using.html

21
Obtaining the Ports Collection (2/3)
● git (1)
○ Install git command line tool
■ sudo pkg install git
○ Checkout from a given repository
■ sudo git clone https://git.FreeBSD.org/ports.git /usr/ports

22
Obtaining the Ports Collection (3/3)
● Port directory
○ /usr/ports/<category>/<name>

$ ls /usr/ports/
CHANGES archivers finance multimedia textproc
CONTRIBUTING.md astro french net ukrainian
COPYRIGHT audio ftp net-im vietnamese
GIDs base games net-mgmt www
Keywords benchmarks german net-p2p x11
LEGAL biology graphics news x11-clocks

$ ls /usr/ports/editors/vim
Makefile distinfo files pkg-descr pkg-plist

23
Ports system (1)
● Find your application
○ cd /usr/ports
○ For the first time, run "sudo make fetchindex" to fetch index for searching
○ make search name=program name
○ make search key=string

$ make search name=vim-console


Port: vim-console-8.2.1558
Path: /usr/ports/editors/vim-console
Info: Improved version of the vi editor (console only)
Maint: [email protected]
B-deps: pkgconf-1.7.3,1
R-deps:
WWW: http://www.vim.org/
24
Ports system (2)
● psearch(1)
○ Simple but useful tool to find ports
○ ports-mgmt/psearch
■ or pkg install psearch
○ psearch <name of port>
■ psearch vim

$ psearch vim
audio/vitunes Curses-based media player with vim-like keybinds
devel/clewn Clewn provides Gdb support within Vim
editors/cream Gvim extension with many features
...

25
Ports system (3)
● Type "make install clean" to install your application
○ make config (/var/db/ports/)
○ make fetch (/usr/ports/distfiles/)
○ make checksum
○ make extract make (all)
○ make patch
○ make configure
○ make build
○ make install
○ make clean
■ Clean files generated by configure process
○ make distclean
■ Clean downloaded distribution files (tarball) 26
Ports system (4)
● The ports system uses fetch(1) to download the files
○ MASTER_SITES environment variable
○ /etc/make.conf
MASTER_SITE_BACKUP?= \
http://FreeBSD.cs.nctu.edu.tw/distfiles/${DIST_SUBDIR}/
MASTER_SITE_OVERRIDE?= ${MASTER_SITE_BACKUP}

● Options for ports


○ make config
■ Won't build or install the port
■ Use this to re-configure ports (otherwise, it uses old one instead)
○ hidden options (not shown in 'make config')
■ Edit the Makefiles under that port directory 27
Ports system (5)
● I have installed the application but Command not found…
○ Logout, and then login.
○ If you use (t)csh or zsh
■ rehash
並不是在ls按下enter當下才去檔案系統中找並抓出來執⾏
事實上,⼀開始就掃過整個檔案系統,就知道有哪些執⾏檔,所以可以在ls
當下,立刻找到ls真正所在的位置並執⾏
所以當新安裝⼀個程式,hash map中還沒有指令,因此要使⽤rehash更新
但現在再安裝完通常會⾃動執⾏rehash

28
Upgrading Ports using Portmaster
● ports-mgmt/portmaster
○ A utility for easily upgrading and installing ports
$ cd /usr/ports/ports-mgmt/portmaster && make install clean
● Install or upgrade a port
○ portmaster <category>/<name>
■ portmaster sysutils/lsof
○ /usr/ports/UPDATING
■ Read before attempting any port upgrades!!!
● Useful options
○ -B, -d, -a, -r, -y, -H, -w
○ portmaster -dyBwH editors/vim
○ /usr/local/etc/portmaster.rc 29
Security
● Show security issues about installed packages
○ No matter from port or from package
○ pkg audit
○ Upgrade these packages to mitigate security problems

$ pkg audit
python38-3.8.10 is vulnerable:
Python -- multiple vulnerabilities
WWW: https://vuxml.FreeBSD.org/freebsd/145ce848-1165-11ec-
ac7e-08002789875b.html

30
Install from source (1)
● Compile the source files first and then install
○ Tarball, a pack of source code
■ tar -xzf certain-source.tar.gz
■ cd certain-source
■ ./configure [options …]
● ./configure --help
■ make
■ make install (root permission)

31
Install from source (2)
● Compile the source files first and then install
○ Checkout master branch from VCS
■ git clone --depth=1 https://github.com/curl/curl.git
■ cd curl
■ ./buildconf
■ ./configure --enable-debug
■ make
■ sudo make install

32
Security Considerations (1)
● How to find secure source
○ Check the official site, read the announcement and change log
○ Verify the checksum (tarball)
○ Fetch via https or ssh (VCS)

33
Security Considerations (2)
● Why "curl URL | sh" is bad?
○ Example: "curl get.pow.cx | sh"
○ Why do you think this is good?
○ Search: "curl pipe bash"
■ Even the file does not contain evil code, broken connection may turn it.
■ "rm -rf /tmp/foo.bar" becomes "rm -rf /"
○ Instead: download the script, read it, execute it.

34
Deinstall Applications
● Two methods
○ pkg delete
■ Find the package name via pkg info
■ Dependency check
■ Disable dependency check
● -f : force
● pkg delete -f <names of packages>
○ make deinstall
■ Change to the port’s directory
■ make deinstall
■ Delete it anyway
■ Similar to "pkg delete -f"
35
Try to install from ports/pkg
● tmux
● vim-console, emacs
● mutt
● wget, curl
● lftp
● lynx, w3m
● expect
● zsh, bash
● sl

36
Appendix
Package management in other Unix-like systems

國立陽明交通⼤學資⼯系資訊中⼼
Information Technology Center, Department of Computer Science, NYCU
Package Manager Rosetta Stone
● Package commands in the most common systems
● https://wiki.freebsd.org/PackageManagerRosettaStone

38

You might also like