How to create your own Linux package from scratch? [duplicate]

How do you create your own package in Linux, just like cd, ls, or any third party package?

All I know is how to create a .sh file, write a script in it and execute it using:

bash file_name

But in addition to that I want to understand in more depth. Please explain the complete steps from downloading using apt-get to how to run it.


I am assuming you want to write a new program and distribute it as a Debian package in Ubuntu.

Suppose you have the bash script, hello, and you have marked it as executable

#!/bin/bash
echo "Hello World"
  1. Now create a Debian package which will place this hello file in /usr/bin. The linked answer is about a single python script, but it works the same way with a bash script. Once installed, it can be run from the terminal with:

    username@computer~$ hello
    
  2. Upload the Debian source to a Launchpad PPA, so that users can add it to their system, and subsequently download it with apt.

  3. You can later submit it to Debian's repositories, so that it can be directly installed in Ubuntu and other derivatives of Debian (although I don't know if Debian maintainers allow simple bash scripts to be added to their repositories. But you can put any program in your own Launchpad PPA).