SHARE
TWEET

hestah

a guest Feb 20th, 2020 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Using apt-get Commands In Linux
  2.  
  3. There are two main tools:
  4.  
  5.  **apt-get** is for installing, upgrading and cleaning packages.
  6.  
  7.  **apt-cache** is used for finding new packages.
  8.  
  9.  
  10. ### Update package database with apt-get
  11.  
  12. apt-get basically works on a database of available packages. If you don’t update this database, the system won’t know if there are newer packages available or not.
  13.  
  14. ```
  15. sudo apt-get update
  16. ```
  17.  
  18. ### Upgrade installed packages with apt-get
  19.  
  20. ```
  21. sudo apt-get upgrade
  22. ```
  23.  
  24. To upgrade only a specific program:
  25.  
  26. ```
  27. sudo apt-get upgrade <package_name>
  28. ```
  29.  
  30. There is another way to provide a complete upgrade by using the command below:
  31.  
  32. ```
  33. sudo apt-get dist-upgrade
  34. ```
  35.  
  36.  dist-upgrade should be avoided on production machines.
  37.  
  38. ### Using apt-cache commands to search for packages
  39.  
  40. ```
  41. apt-cache search <search term>
  42. ```
  43.  
  44. If you just want to search the packages with specific package names, you can use the command below:
  45.  
  46. ```
  47. apt-cache pkgnames <search_term>
  48. ```
  49.  
  50.  get more information about a package such as version, dependencies etc by using the command below:
  51.  
  52. ```
  53. apt-cache showpkg <package_name>
  54. ```
  55.  
  56. ### How to install new packages with apt-get
  57.  
  58. If you know the name of the package, you can easily install it using the command below. Replace the <package_name> with your desired package.
  59.  
  60. ```
  61. sudo apt-get install <package_name>
  62. ```
  63.  
  64.  Suppose I want to install Pinta image editor, all I need to do is to use the command below:
  65.  
  66. ```
  67. sudo apt-get install pinta
  68. ```
  69. Type a few letters and press tab and it will suggest all the packages available with those letters.
  70.  
  71. ##### How to install multiple packages
  72.  
  73. You can install several packages at a time by providing their names:
  74.  
  75. ```
  76. sudo apt-get install <package_1> <package_2> <package_3>
  77. ```
  78.  
  79. ##### How to install packages without upgrading
  80.  
  81. Suppose for some reason you want to install a package but don’t want to upgrade it if it is already installed.
  82.  
  83. ```
  84. sudo apt-get install <package_name> --no-upgrade
  85. ```
  86.  
  87. ##### How to only upgrade packages, not install it
  88.  
  89. In case you only want to upgrade a package but don’t want to install it (if it’s not already installed), you can do that with the following command:
  90.  
  91. ```
  92. sudo apt-get install <package_name> --only-upgrade
  93. ```
  94.  
  95. ##### How to install a specific version of an application
  96.  
  97.  
  98. ```
  99. sudo apt-get install <package_name>=<version_number>
  100. ```
  101.  
  102. ### How to remove installed packages with apt-get
  103.  
  104. ```
  105. sudo apt-get remove <package_name>
  106. ```
  107.  
  108. Auto-completion works here as well.
  109.  
  110. ```
  111. sudo apt-get purge <package_name>
  112. ```
  113.  
  114. ##### What is the difference between apt-get remove and apt-get purge?
  115.  
  116. - apt-get remove just removes the binaries of a package. It doesn’t touch the configuration files
  117. - apt-get purge removes everything related to a package including the configuration files
  118.  
  119.  
  120. ### How to clean your system with apt-get
  121.  
  122. You can use the command below to clean the local repository of retrieved package files:
  123.  
  124. ```
  125. sudo apt-get clean
  126. ```
  127.  
  128. Autoclean only removes those retrieved package files that have a newer version now and they won’t be used anymore.
  129.  
  130. ```
  131. sudo apt-get autoclean
  132. ```
  133.  
  134. It removes libs and packages that were installed automatically to satisfy the dependencies of an installed package. If the package is removed, these automatically installed packages are useless in the system. This command removes such packages.
  135.  
  136. ```
  137. sudo apt-get autoremove
  138. ```
  139.  
  140. ------
  141.  
  142. ## Uptime
  143.  
  144. ### Finding the uptime in Linux ###
  145.  
  146. To find the uptime in Linux, use the *uptime* command.
  147.  
  148. ```
  149. user@user-Inspiron-3185:~$ uptime
  150.  18:29:59 up 12:11,  1 user,  load average: 1.54, 1.45, 1.85
  151. user@user-Inspiron-3185:~$
  152. ```
  153.  
  154. This result gives the current time, the amount of time since boot, # of users on and load information.
  155.  
  156. To get the actual amount of time it has been up instead of the time it was when the machine was last booted, use *-s*.
  157.  
  158. ```
  159. user@user-Inspiron-3185:~$ uptime -s
  160. 2020-02-02 06:18:45
  161. user@user-Inspiron-3185:~$
  162. ```
  163.  
  164. In this example, the machine has been on for 6 hours and 18 minutes.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top