Showing posts with label apt-get. Show all posts
Showing posts with label apt-get. Show all posts

Wednesday, February 14, 2018

what is the difference between apt-get remove and purge and autoremove in ubuntu?

apt-get remove vs  purge vs autoremove

Let's explain this by taking wget package as the one to be removed.
remove

apt-get remove wget
This removes the wget binaries, but it's configuration files and installed dependencies will remain in the system.
purge

apt-get purge wget
This removes the package as well as its configuration files. But the dependencies will remain in the system. However, configuration files in the home directory won't get removed.
This command is same as using --purge option with the above remove command.
autoremove

apt-get autoremove wget
This will remove the package as well as its dependencies, if those dependencies aren't used by other packages.
apt-get autoremove
If the package name is not specified with autoremove, it will remove all the unused dependencies in the system.

Saturday, June 6, 2015

How To Install Java on Ubuntu with Apt-Get



Introduction

As a lot of  programs require to have Java installed, this article will guide you through the process of installing and managing different versions of Java.

Installing default JRE/JDK
This is the recommended and easiest option. This will install OpenJDK 6 on Ubuntu 12.04 and earlier and on 12.10+ it will install OpenJDK 7.

Installing Java with apt-get is easy. First, update the package index:

sudo apt-get update
Then, check if Java is not already installed:

java -version
If it returns "The program java can be found in the following packages", Java hasn't been installed yet, so execute the following command:

sudo apt-get install default-jre

This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), which is usually needed to compile Java applications (for example Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA execute the following command:

sudo apt-get install default-jdk
That is everything that is needed to install Java.

All other steps are optional and must only be executed when needed.

Installing OpenJDK 7 (optional)
To install OpenJDK 7, execute the following command:

sudo apt-get install openjdk-7-jre

This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), execute the following command:

sudo apt-get install openjdk-7-jdk

Installing Oracle JDK (optional)
The Oracle JDK is the official JDK; however, it is no longer provided by Oracle as a default installation for Ubuntu.

You can still install it using apt-get. To install any version, first execute the following commands:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

Then, depending on the version you want to install, execute one of the following commands:

Oracle JDK 6

This is an old version but still in use.

sudo apt-get install oracle-java6-installer
Oracle JDK 7

This is the latest stable version.

sudo apt-get install oracle-java7-installer
Oracle JDK 8

This is a developer preview, the general release is scheduled for March 2014. This external article about Java 8 may help you to understand what it's all about.

sudo apt-get install oracle-java8-installer
Managing Java (optional)
When there are multiple Java installations on your Droplet, the Java version to use as default can be chosen. To do this, execute the following command:

sudo update-alternatives --config java

It will usually return something like this if you have 2 installations (if you have more, it will of course return more):

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      manual mode

Press enter to keep the current choice[*], or type selection number:
You can now choose the number to use as default. This can also be done for the Java compiler (javac):

sudo update-alternatives --config javac

It is the same selection screen as the previous command and should be used in the same way. This command can be executed for all other commands which have different installations. In Java, this includes but is not limited to: keytool, javadoc and jarsigner.

Setting the "JAVA_HOME" environment variable
To set the JAVA_HOME environment variable, which is needed for some programs, first find out the path of your Java installation:

sudo update-alternatives --config java
It returns something like:

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      manual mode

Press enter to keep the current choice[*], or type selection number:
The path of the installation is for each:

/usr/lib/jvm/java-7-oracle

/usr/lib/jvm/java-6-openjdk-amd64

/usr/lib/jvm/java-7-oracle

Copy the path from your preferred installation and then edit the file /etc/environment:

sudo nano /etc/environment

In this file, add the following line (replacing YOUR_PATH by the just copied path):

JAVA_HOME="YOUR_PATH"
JAVA_HOME=” /usr/lib/jvm/java-7-openjdk-amd64”
That should be enough to set the environment variable. Now reload this file:

source /etc/environment

Test it by executing:

echo $JAVA_HOME


If it returns the just set path, the environment variable has been set successfully. 

Sunday, May 17, 2015

Ubuntu apt-get & apt-cache commands



Apt-get & apt-cache are the command line package management utility in Ubuntu Linux. GUI version of apt-get command is the Synaptic Package Manager, in this post we are going to discuss 15 different examples of apt-get & apt-cache commands.

Example:1 List of all the available packages
ubuntu@localhost:~$ apt-cache pkgnames
account-plugin-yahoojp
ceph-fuse
dvd+rw-tools
e3
gnome-commander-data
grub-gfxpayload-lists
gweled
.......................................

Example:2 Search Packages using keywords
This command is very helpful when you are not sure about package name , just enter the keyword and apt-get command will list packages related to the keyword.
ubuntu@localhost:~$ apt-cache search "web server"
apache2 - Apache HTTP Server
apache2-bin - Apache HTTP Server (binary files and modules)
apache2-data - Apache HTTP Server (common files)
apache2-dbg - Apache debugging symbols
apache2-dev - Apache HTTP Server (development headers)
apache2-doc - Apache HTTP Server (on-site documentation)
apache2-utils - Apache HTTP Server (utility programs for web servers)
......................................................................
Note: If you have installed “apt-file” package then we can also search the package using config files as shown below :
ubuntu@localhost:~$ apt-file search nagios.cfg
ganglia-nagios-bridge: /usr/share/doc/ganglia-nagios-bridge/nagios.cfg
nagios3-common: /etc/nagios3/nagios.cfg
nagios3-common: /usr/share/doc/nagios3-common/examples/nagios.cfg.gz
pnp4nagios-bin: /etc/pnp4nagios/nagios.cfg
pnp4nagios-bin: /usr/share/doc/pnp4nagios/examples/nagios.cfg

Example:3 Display the basic information of Specific package.
ubuntu@localhost:~$ apt-cache show postfix
Package: postfix
Priority: optional
Section: mail
Installed-Size: 3524
Maintainer: LaMont Jones <lamont@debian.org>
Architecture: amd64
Version: 2.11.1-1
Replaces: mail-transport-agent
Provides: default-mta, mail-transport-agent
.....................................................
Example:4 List the dependency of Package.
ubuntu@localhost:~$ apt-cache depends postfix
postfix
 Depends: libc6
 Depends: libdb5.3
 Depends: libsasl2-2
 Depends: libsqlite3-0
 Depends: libssl1.0.0
 |Depends: debconf
 Depends: <debconf-2.0>
 cdebconf
 debconf
 Depends: netbase
 Depends: adduser
 Depends: dpkg
............................................
Example:5 Display the Cache Statistics using apt-cache.
ubuntu@localhost:~$ apt-cache stats
Total package names: 60877 (1,218 k)
Total package structures: 102824 (5,758 k)
 Normal packages: 71285
 Pure virtual packages: 1102
 Single virtual packages: 9151
 Mixed virtual packages: 1827
 Missing: 19459
Total distinct versions: 74913 (5,394 k)
Total distinct descriptions: 93792 (2,251 k)
Total dependencies: 573443 (16.1 M)
Total ver/file relations: 78007 (1,872 k)
Total Desc/File relations: 93792 (2,251 k)
Total Provides mappings: 16583 (332 k)
Total globbed strings: 171 (2,263 )
Total dependency version space: 2,665 k
Total slack space: 37.3 k
Total space accounted for: 29.5 M
Example:6 Update the package repository using “apt-get update”
Using the command “apt-get update” , we can resynchronize the package index files from their sources repository. Package index are retrieved from the file located at “/etc/apt/sources.list”
ubuntu@localhost:~$ sudo apt-get update
 Ign http://extras.ubuntu.com utopic InRelease
 Hit http://extras.ubuntu.com utopic Release.gpg
 Hit http://extras.ubuntu.com utopic Release
 Hit http://extras.ubuntu.com utopic/main Sources
 Hit http://extras.ubuntu.com utopic/main amd64 Packages
 Hit http://extras.ubuntu.com utopic/main i386 Packages
 Ign http://in.archive.ubuntu.com utopic InRelease
 Ign http://in.archive.ubuntu.com utopic-updates InRelease
 Ign http://in.archive.ubuntu.com utopic-backports InRelease
 ................................................................
Example:7 Install a package using apt-get command.
ubuntu@localhost:~$ sudo apt-get install icinga
In the above example we are installing a package named “icinga”

Example:8 Upgrade all the Installed Packages

ubuntu@localhost:~$ sudo apt-get upgrade

Example:9 Upgrade a Particular Package.

“install” option along with “–only-upgrade” in apt-get command is used to upgrade a particular package , example is shown below :
ubuntu@localhost:~$ sudo apt-get install filezilla --only-upgrade

Example:10 Removing a package using apt-get command.

ubuntu@localhost:~$ sudo apt-get remove skype
Above command will remove or delete the skype package only , if you want to delete its config files then use the “purge” option in the apt-get command. Example is shown below :
ubuntu@localhost:~$ sudo apt-get purge skype
We can also use the combination of above commands :
ubuntu@localhost:~$ sudo apt-get remove --purge skype

Example:11 Download the package in the Current Working Directory

ubuntu@localhost:~$ sudo apt-get download icinga
Get:1 http://in.archive.ubuntu.com/ubuntu/ utopic/universe icinga amd64 1.11.6-1build1 [1,474 B]
Fetched 1,474 B in 1s (1,363 B/s)
Above command will download icinga package in your current working directory.

Example:12 Clear disk Space used by retrieved package files.

ubuntu@localhost:~$ sudo apt-get clean
Above Command will clear the disk space used by apt-get command while retrieving(download) packages.
We can also use “autoclean” option in place of “clean“, the main difference between them is that autoclean removes package files that can no longer be downloaded, and are largely useless.
ubuntu@localhost:~$ sudo apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done

Example:13 Remove Packages using “autoremove” option.

When we use “autoremove” option with apt-get command , then it will remove the packages that were installed to satisfy the dependency of other packages and are now no longer needed or used.
ubuntu@localhost:~$ sudo apt-get autoremove icinga

Example:14 Display Changelog of a Package.

ubuntu@localhost:~$ sudo apt-get changelog apache2
Get:1 Changelog for apache2 (http://changelogs.ubuntu.com/changelogs/pool/main/a/apache2/apache2_2.4.10-1ubuntu1/changelog) [195 kB]
Fetched 195 kB in 3s (60.9 kB/s)
Above Command will download the changelog of apache2 package and will display through sensible-pager on your screen.

Example:15 List broken dependencies using “check” option

ubuntu@localhost:~$ sudo apt-get check
Reading package lists... Done
Building dependency tree
Reading state information... Done