Skip to content

Instantly share code, notes, and snippets.

@cham11ng
Last active October 22, 2023 13:01
Show Gist options
  • Save cham11ng/c44b84bbb1aa308bb9a73f946492d9d1 to your computer and use it in GitHub Desktop.
Save cham11ng/c44b84bbb1aa308bb9a73f946492d9d1 to your computer and use it in GitHub Desktop.
Linux (Ubuntu) Configuration

Linux Configuration

By: Sagar Chamling

First Upgrade

sudo apt update
sudo apt upgrade

GNOME Shell on Ubuntu (Not required)

sudo apt install gnome-shell
sudo apt install gnome-tweak-tool
sudo apt install gtk2-engines-pixbuf
sudo apt install gnome-themes-standard

Install Developer Firefox, Chromimum Browser, Vim, Sublime Text

Install Firefox Developer Edition from PPA
sudo add-apt-repository ppa:ubuntu-mozilla-daily/firefox-aurora
sudo apt-get update
sudo apt-get install firefox
Install Chromium Browser, Vim, Sublime Text
wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
sudo apt-get update

sudo apt install chromium-browser
sudo apt install vim
sudo apt install vlc browser-plugin-vlc
sudo apt install sublime-text
  • Customization of Sublime Text

    • Install Package Control Ctrl + Shift + P, Search Install Package Control
    • Install Material Theme
    • Install zz File Icons

Configure Git SSH and LEMP Setup

sudo apt install git

Composer Setup

This will download the newest version of composer. Composer Setup File

  • Download this .sh file
  • Set permission and run shell script file
  • You may check the version
$ chmod 755 setupcomposer.sh

$ ./setupcomposer.sh 
[sudo] password for cham11ng: 
All settings correct for using Composer
Downloading...

Composer (version 1.3.1) successfully installed to: /usr/bin/composer
Use it: php /usr/bin/composer

$ composer --version
Composer version 1.3.1 2017-01-07 18:08:51

$ sudo chown -R <username>:<username> ~/.composer

Change Ownership from root to username

Laravel Setup

$ composer global require "laravel/installer" -vvv

Make sure to place the ~/.composer/vendor/bin directory (or the equivalent directory for your OS) in your PATH so the laravel executable can be located by your system.

ie. add the following line at the end of ~/.bashrc

export PATH=~/.composer/vendor/bin:$PATH

You need to reboot your .bashrc

source ~/.bashrc

Once installed, the laravel new command will create a fresh Laravel installation in the directory you specify. For instance, laravel new blog will create a directory named blog containing a fresh Laravel installation with all of Laravel's dependencies already installed. This method of installation is much faster than installing via Composer:

laravel new blog

Yarn Setup

  • You will first need to configure the repository
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
  • You will also need to configure the NodeSource repository to get a new enough version of Node.js
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt install -y nodejs

sudo apt update && sudo apt install yarn

PHPUnit Setup

To globally install the PHAR:

wget https://phar.phpunit.de/phpunit-6.1.phar
chmod +x phpunit-6.1.phar
sudo mv phpunit-6.1.phar /usr/local/bin/phpunit
phpunit --version

Live Reload Setup (Useful to Web Designer)

Install this extension in Chrome. LiveReload You need to install ruby to use gem

sudo apt install ruby-full

sudo gem install bundler

sudo gem install guard-livereload

sudo gem install rb-inotify

guard init

sudo apt install python3-livereload

Just install python3-livereload to make it work. Live reload in working directory

$ livereload
[I 170124 13:06:44 server:271] Serving on http://127.0.0.1:35729
[I 170124 13:06:44 handlers:58] Start watching changes

Hit url in browser.

FileZilla Install

sudo sh -c 'echo "deb http://archive.getdeb.net/ubuntu xenial-getdeb apps" >> /etc/apt/sources.list.d/getdeb.list'

wget -q -O - http://archive.getdeb.net/getdeb-archive.key | sudo apt-key add -

sudo apt install filezilla

Zeal Install - is an offline documentation browser for software developers

sudo add-apt-repository ppa:zeal-developers/ppa

sudo apt update

sudo apt install zeal

HTTPie Install

sudo apt install httpie

TLP Setup

sudo add-apt-repository ppa:linrunner/tlp
sudo apt-get update
sudo apt-get install tlp tlp-rdw 

Python and Django Install

Shell Aliases

References

Oracle JDK Install

sudo add-apt-repository ppa:webupd8team/java

tar -zxvf jdk*.*.*_***

sudo mkdir -p /usr/local/java

sudo mv jdk*.*.*_***/ /usr/local/java/

sudo vim /etc/profile

Add these lines.

JAVA_HOME=/usr/local/java/jdk*.*.*_***
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk*.*.*_***/bin/java" 1

OR

Remove OpenJDK

sudo apt-get remove openjdk*

Add the PPA and install Oracle Java 8 with following 3 commands.

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install java-common oracle-java8-installer

During the installation process you will need to accept the Oracle License agreement. Once installed we need to set Java environment variables such as JAVA_HOME on Ubuntu 16.04/17.04.

sudo apt-get install oracle-java8-set-default
source /etc/profile

Check java -version

References

Update Python and Create Local Programming Environment and Django

Install zlib

sudo apt-get install zlib1g-dev

Update Python

Step - 1: Download

$ wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz

Step - 2: Unpack

$ tar xfz Python-3.6.1.tar.gz

Step - 3: Configure

$ cd Python-3.6.1/
$ ./configure --prefix /usr/local/lib/python3.6.1 --enable-ipv6
$ ./configure --enable-optimizations

Step - 4: Build

$ make

Step - 5: Deploy

$ sudo make install

Use the command python3 instead of python, and pip3 instead of pip.

Step - 6: Check Version

$ python3 -V
Python 3.6.0

Manage Software Package

Step - 1: Install pip:

$ sudo apt install -y python3-pip

Step - 2: Setting Virtual Environemnt

$ sudo apt install -y python3-venv

Step - 3: Few more packages and development tools

$ sudo apt install build-essential libssl-dev libffi-dev python3-dev

Step - 4: Ready to create environments

$ mkdir environments

$ cd environments

$ python3 -m venv {name_of_env} --without-pip

Step - 5: To use this environment

$ source {name_of_env}/bin/activate

Your prompt will now be prefixed with the name of your environment

({name_of_env}) cham11ng@aspire:~/environments$ 

Create Simple Program

Step - 1: Create a file hello.py

$ vim hello.py

Step - 1.1: Type Code

prinf("Hello World ! ");

Press ESC key and type :wq to write and exit

Step - 2: Run Program

$ python3 hello.py

Leave an environment

$ deactivate

References

Redis Install

Installing Redis on an Ubuntu. Run the command below to install Redis on your machine:

sudo apt-get install redis-server

If you are planning on using Redis as an object cache for PHP-based application, you need to install the following package too:

sudo apt-get install php-redis

Configure Redis as a cache on Ubuntu 16.04

To configure Redis as a cache you need to edit the /etc/redis/redis.conf file. We will use nano as a text editor for this purpose, but you can use any text editor of your choice.

sudo nano /etc/redis/redis.conf

To configure the max memory for Redis as well as how Redis will select what to remove when the max memory is reached, add the following lines at the end of the file:

maxmemory 128mb
maxmemory-policy allkeys-lru

In this example, Redis will remove any key according to the LRU algorithm when the max memory of 128mb is reached. Save and close the file, then restart the Redis service:

sudo systemctl restart redis-server.service

Next, enable Redis on system boot:

sudo systemctl enable redis-server.service
#!/bin/sh
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
exit 1
fi
sudo php composer-setup.php --install-dir=/usr/bin --filename=composer
RESULT=$?
rm composer-setup.php
exit $RESULT

Create Important aliases for your shell for developer

  • Open Terminal Ctrl + Alt + T
sudo apt install xclip
vim ~/.bash_aliases
  • Add this line

For linux,

alias sshkey="cat ~/.ssh/id_rsa.pub | xclip -selection clipboard && echo 'Public SSH copied to clipboard.'"

For mac,

alias sshkey="cat ~/.ssh/id_rsa.pub | pbcopy && echo 'Public SSH copied to clipboard.'"
  • Save the file, you'll need to "reboot" the aliases
source ~/.bash_aliases
  • Now you can user sshkey to copy id_rsa.pub

  • Then simply Ctrl + V

Some of my aliases

alias sshkey="cat ~/.ssh/id_rsa.pub | xclip -selection clipboard && echo 'Public SSH copied to clipboard.'"

alias gs="git status"
alias gsl="git stash list"
alias ga="git add"
alias gaa="git add ."
alias gc="git commit"
alias gl="git log --oneline --graph"
alias glf="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
alias nah="git reset --hard; git clean -df;"
alias co="git checkout"

alias art="php artisan"
alias serve="php artisan serve"
alias tinker="php artisan tinker"
alias migrate="php artisan migrate"
alias routes="php artisan route:list"

alias update="sudo apt update"
alias upgrade="sudo apt full-upgrade"
alias list="apt list --upgradable"

alias pclear="php artisan optimize && php artisan cache:clear && php artisan config:clear && php artisan route:clear && php artisan view:clear"

Don't forget to reboot aliaes

source ~/.bash_aliases

Thanks to Jeffrey Way

Sublime Text Setting

Key Binding

[
	{ "keys": ["alt+1"], "command": "toggle_side_bar" },
	{ "keys": [":", "v", "s", "p"], "command": "create_pane", "args": {"direction": "right", "give_focus": true} },
	{ "keys": [":", "s", "p"], "command": "create_pane", "args": {"direction": "down", "give_focus": true} },
	{ "keys": [":", "v", "d"], "command": "destroy_pane", "args": {"direction": "self"} },
	{ "keys": ["ctrl+shift+alt+n"], "command": "advanced_new_file_new"},
	{ "keys": ["ctrl+shift+o"], "command": "find_all_under" },
	{ "keys": ["f9"], "command": "expand_fqcn"},
	{ "keys": ["ctrl+alt+l"], "command": "reindent", "args": {"single_line": false} }
]

Setting

{
	"bold_folder_labels": true,
	"font_size": 10,
	"line_padding_bottom": 6,
	"line_padding_top": 6,
	"overlay_scroll_bars": "enabled",
	"theme": "Material Behave.sublime-theme",
	"tab_size": 2,
	"translate_tabs_to_spaces": true,
	"save_on_focus_lost": true,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment