Adding auto complete for apt-get install

Question:

I have noticed that while on Ubuntu, if I type the following:

mc

and it isnt installed, I get the message below:

The program 'mc' is currently not installed. You can install it by typing: sudo apt-get install mc

However in Debian, that is not available. It just gives a “-bash: /usr/bin/mc: No such file or directory” message. How can I implement the same functionality in bash command line on Debian? Yes, I know that if it is package suggestion that I want, I can simply do a regex search using *apt-cache search*. However I was hoping for the simpler suggestion immediately on typing the name of the program.

As per discussions, the functionality is provided by the package command-not-found. However even after installing it, and also installing bash-completion package, this isnt available on the Debian bash shell.

Answer:

The suggestions are definitely provided by the package command-not-found.

However after installing the package, one needs to run the following command once to initialize the database:

update-command-not-found

After doing this, bash starts providing suggestions to install the correct package.

$htop
Could not find the database of available applications, run update-command-not-found as root to fix this
htop: command not found

$update-command-not-found
Downloading complete file http://ftp.de.debian.org/debian/dists/squeeze/Contents-i386.gz
I: Writing data for ftp.de.debian.org_debian_dists_squeeze_Contents-i386.gz ... . done

$htop
The program 'htop' is currently not installed. You can install it by typing:
apt-get install htop
htop: command not found

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.
Install LAMP on Debian

Install LAMP on Debian

LAMP stands for Linux, Apache, MySQL and PHP.

Installing on Debian is easy. Simply follow the following steps. We will be installing MySql, followed by Apache, PHP and Phpmyadmin.

First update the apt repo:

su
apt-get update

 Install MySQL:

apt-get install mysql-server mysql-client

At this point, you will be prompted to install mysql root password three times.

 

Install Apache2:

apt-get install apache2 apache2-doc

To run content from your user directory, do the following:

Enable the module:

a2enmod userdir
/etc/init.d/apache2 restart

Now edit /etc/apache2/mods-enabled/userdir.conf

emacs /etc/apache2/mods-enabled/userdir.conf

Make sure that it looks like this:

<IfModule mod_userdir.c>
        UserDir public_html
        UserDir disabled root

        <Directory /home/*/public_html>
                AllowOverride All
                Options MultiViews Indexes SymLinksIfOwnerMatch
                <Limit GET POST OPTIONS>
                        Order allow,deny
                        Allow from all
                </Limit>
                <LimitExcept GET POST OPTIONS>
                        Order deny,allow
                        Deny from all
                </LimitExcept>
        </Directory>
</IfModule>

Note that you will have to delete parts of a few lines. Or you can exec the following:

sudo cat /etc/apache2/mods-enabled/userdir.conf | sed 's/AllowOverride FileInfo.*/AllowOverride All/' >test.txt
sudo mv test.txt /etc/apache2/mods-enabled/userdir.conf
sudo cat /etc/apache2/mods-enabled/userdir.conf | sed 's/Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec.*/Options MultiViews Indexes SymLinksIfOwnerMatch/' >test.txt
sudo mv test.txt /etc/apache2/mods-enabled/userdir.conf

which does the edit automatically.

Now as normal user, create a public_html folder:

exit
mkdir /home/$USER/public_html

Now change group and restart the web server:

su
chgrp www-data /home/$USER/public_html
service apache2 restart

 Install PHP:

apt-get install php5 php5-mysql libapache2-mod-php5

To allow running php scripts from user directories, Configure the file  /etc/apache2/mods-available/php5.conf :

emacs /etc/apache2/mods-available/php5.conf
<IfModule mod_php5.c>
    <FilesMatch "\.ph(p3?|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    # To re-enable php in user directories comment the following lines
    # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
    # prevents .htaccess files from disabling it.
    #<IfModule mod_userdir.c>
    #    <Directory /home/*/public_html>
    #        php_admin_value engine Off
    #    </Directory>
    #</IfModule>
</IfModule>

As mentioned in the instructions in this file, you need to comment out the later part.

Check that everything works:

Check that public_html can be accessed from localhost.

Create a file index.html in ~/public_html:

<html>

<h2>
Test succeeded
</h2>

</html>

Now, type in the browser address bar:

http://localhost/~droidzone/

If all goes well, you should get the success message.

Now test php. Create the file ~/public_html/phptest.php:

<?php
phpinfo();
?>

Now restart the web server

sudo service apache2 restart

and enter the following address in the browser:

http://localhost/~droidzone/phptest

Of course you have to replace your username for droidzone.

If it gives an error message or the file browser is displayed instead of a webpage, recheck the instructions. If they were correct, in most cases, you need to just restart apache2 service.

Optionally, you can install Perl or Python:

Install Perl:

apt-get install perl libapache2-mod-perl2

Install Python:

apt-get install python libapache2-mod-python

Install Phpmyadmin:

apt-get install phpmyadmin

When prompted, select Apache2 as the web server to be reconfigured automatically.
phpmyadmin.jpg

Also, choose Yes when asked to create a default database.

Configure a passwordless login with phpmyadmin (Not recommended, Optional):

cat /etc/phpmyadmin/config.inc.php | grep -ni --color 'AllowNoPassword'
65:    // $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;
94:// $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;

Now change the Line #65 (the first hit) to remove the comment tag at the beginning.

You can login to phpmyadmin at http://localhost/phpmyadmin

Note that the username it automatically inputs is your username. However such a user doesnt exist. You can login as root.

Additional Info:

Enabling PHP Debugging:

sudo emacs /etc/php5/apache2/php.ini

and turn on display_errors.

If you dont know what line it is on:

grep 'display_errors' /etc/php5/apache2/php.ini

to find out the line:

[[email protected] ~]$ grep 'display_errors' /etc/php5/apache2/php.ini
99:; display_errors
534:display_errors = Off
537:; separately from display_errors. PHP's default behavior is to suppress those

You can even execute the following command to make it write the proper value for debugging:

cat /etc/php5/apache2/php.ini | sed 's/display_errors = Off/display_errors = On/' > test ; mv test /etc/php5/apache2/php.ini

 

References:

  1. Debian Wiki

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Install Oracle Java JDK on Debian

Get the source file from Oracle.Since I used JDK 7, I visited this page and downloaded jdk-7u10-linux-i586.tar.gz (for Linux x86).

Extract it somewhere

curl -J -O -C - http://download.oracle.com/otn-pub/java/jdk/7u10-b18/jdk-7u10-linux-i586.tar.gz?AuthParam=1355492655_c33bc95a6d13e7345ba318a0b46bcc4a
mv jdk-7u10-linux-i586.tar.gz?AuthParam=1355492655_c33bc95a6d13e7345ba318a0b46bcc4a jdk-7u10-linux-i586.tar.gz
tar -xvvf jdk-7u10-linux-i586.tar.gz

Perform the installation:

sudo mv ./jdk1.7.0_10 /usr/lib/jvm/jdk1.7.0
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1

Now choose the correct version of the programs if you have more than installed (as is most likely the case as the OS often comes with a version, and you install another). This is to avoid the error message that states that the version of java and javac clash (or something similiar).

sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws

 

[[email protected] droidzone]# sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                            Priority   Status
------------------------------------------------------------
  0            /usr/bin/gij-4.4                 1044      auto mode
  1            /usr/bin/gij-4.4                 1044      manual mode
* 2            /usr/lib/jvm/jdk1.7.0/bin/java   1         manual mode

Press enter to keep the current choice[*], or type selection number:

As noted, I’ve chosen the version I just installed, which is jdk1.7.0.

Depending on the versions you have installed, you may need to repeat similiarly for:

[[email protected] droidzone]# sudo update-alternatives --config javac
There is only one alternative in link group javac: /usr/lib/jvm/jdk1.7.0/bin/javac
Nothing to configure.

And:

[[email protected] droidzone]# sudo update-alternatives --config javaws
There is only one alternative in link group javaws: /usr/lib/jvm/jdk1.7.0/bin/javaws
Nothing to configure.

You will notice that since I had only single versions of javac and javaws, I didnt need to choose another one. It may just be worthwhile to try these commands anyway.

Confirm that the version of java and javac correspond:

[[email protected] droidzone]# `which java` -version
java version "1.7.0_10"
Java(TM) SE Runtime Environment (build 1.7.0_10-b18)
Java HotSpot(TM) Server VM (build 23.6-b04, mixed mode)

[[email protected] droidzone]# `which javac` -version
javac 1.7.0_10
[[email protected] droidzone]#

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.