Last active
November 8, 2024 10:42
-
-
Save mzaidannas/f537446be1e71b71aa6bcffefad62b80 to your computer and use it in GitHub Desktop.
Ubuntu Initial Setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Configure some system specifications | |
sudo usermod -G input -a $USER | |
# Max number of files (Required by services like docker/jvm) | |
sudo sysctl -w fs.inotify.max_user_watches=524288 | |
sudo sysctl -w vm.max_map_count=262144 | |
# Better swap if system have a lot of unused memory | |
sudo sysctl -w vm.swappiness=10 | |
sudo sysctl -w vm.vfs_cache_pressure=100 | |
# Better USB transfer speed/progress | |
sudo sysctl -w vm.dirty_bytes=50331648 | |
sudo sysctl -w vm.dirty_background_bytes=16777216 | |
# Make these changes permanent | |
echo "fs.inotify.max_user_watches=524288\nvm.max_map_count=262144" | sudo tee /etc/sysctl.d/20-max-files.conf | |
echo "vm.swappiness=10\nvm.vfs_cache_pressure=100" | sudo tee /etc/sysctl.d/40-swap.conf | |
echo "vm.dirty_bytes=50331648\nvm.dirty_background_bytes=16777216" | sudo tee /etc/sysctl.d/50-usb-transfer.conf | |
sudo apt update && sudo apt upgrade -y | |
# Install common tools and utilities | |
sudo apt install -y unace unrar zip unzip p7zip-full p7zip-rar sharutils rar uudeview mpack arj cabextract zsh samba gpg sudo wget curl | |
# Set samba password | |
(echo "$password"; echo "$password") | sudo smbpasswd -s -a $USER | |
# Change default shell | |
sudo chsh -s /bin/zsh $(whoami) | |
# GPG keys for extra repos | |
sudo install -dm 755 /etc/apt/keyrings | |
# Nodejs | |
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg | |
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list | |
sudo apt install -y nodejs | |
sudo npm install -g yarn eslint stylelint coffeelint htmlhint prettier | |
# Postgresql | |
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/keyrings/postgresql.gpg | |
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/postgresql.gpg] http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list | |
sudo apt update && sudo apt install -y postgresql libpq-dev | |
sudo systemctl restart postgresql | |
sudo systemctl enable postgresql | |
sudo -u postgres psql -U postgres -d postgres -c "ALTER USER postgres WITH PASSWORD '$password';" | |
# Redis | |
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/redis-archive-keyring.gpg | |
echo "deb [signed-by=/etc/apt/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list | |
sudo apt update && sudo apt install -y redis | |
sudo systemctl restart redis-server | |
sudo systemctl enable redis-server | |
# Memcached | |
sudo apt install -y memcached | |
sudo systemctl restart memcached | |
sudo systemctl enable memcached | |
# MongoDB | |
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | sudo gpg --dearmor -o /etc/apt/keyrings/mongodb-server-7.0.gpg | |
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/mongodb-server-7.0.gpg] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list | |
sudo apt update && sudo apt install -y mongodb-org | |
sudo systemctl restart mongod | |
sudo systemctl enable mongod | |
# Elasticsearch | |
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /etc/apt/keyrings/elastic.gpg | |
echo "deb [signed-by=/etc/apt/keyrings/elastic.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list | |
sudo apt update && sudo apt install -y elasticsearch | |
# Only use 2 GB of heap memory | |
echo "-Xms2g\n-Xmx2g" | sudo tee /etc/elasticsearch/jvm.options.d/heap_size.options | |
sudo systemctl restart elasticsearch | |
sudo systemctl enable elasticsearch | |
# Docker | |
sudo apt purge -y docker docker-engine docker.io containerd runc | |
sudo apt install -y \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
gnupg-agent \ | |
software-properties-common | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg | |
echo "deb [signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list | |
sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io | |
sudo systemctl restart docker | |
sudo systemctl enable docker | |
# Install build tools and programming languages | |
sudo apt install -y build-essential git git-lfs gitk openssl python3 python3-setuptools python3-pip libssl-dev resolvconf default-jre default-jdk llvm clang clang-tools lldb lld cmake gradle ruby ruby-build rust-all golang | |
# Install mise and configure ruby, nodejs, python and java plugins | |
wget -qO - https://mise.jdx.dev/gpg-key.pub | gpg --dearmor | sudo tee /etc/apt/keyrings/mise-archive-keyring.gpg 1> /dev/null | |
echo "deb [signed-by=/etc/apt/keyrings/mise-archive-keyring.gpg arch=amd64] https://mise.jdx.dev/deb stable main" | sudo tee /etc/apt/sources.list.d/mise.list | |
sudo apt update | |
sudo apt install -y mise | |
tee -a ~/.profile << MISE | |
# mise version manager | |
eval "$(mise activate bash --shims)" | |
MISE | |
tee -a ~/.zprofile << MISE | |
# mise version manager | |
eval "$(mise activate zsh --shims)" | |
MISE | |
# Some legacy tools still require asdf. So emulate asdf using mise | |
ln -s ~/.local/share/mise ~/.asdf | |
sudo ln -s ~/.local/share/mise/.fake-asdf/asdf /usr/bin/asdf | |
mise plugins install nodejs https://github.com/asdf-vm/asdf-nodejs.git | |
mise plugins install ruby https://github.com/asdf-vm/asdf-ruby.git | |
mise plugins install python https://github.com/asdf-community/asdf-python.git | |
# Use vscode as default editor | |
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg | |
sudo install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/ | |
rm microsoft.gpg | |
echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" | sudo tee /etc/apt/sources.list.d/vscode.list | |
sudo apt update && sudo apt install -y code | |
# Use helix as default command line text editor | |
sudo add-apt-repository -y ppa:maveonair/helix-editor | |
sudo apt install -y helix | |
# User dbeaver community as default database gui | |
sudo add-apt-repository -y ppa:serge-rider/dbeaver-ce | |
sudo apt install -y dbeaver-ce | |
# Alias commands (Better commandline tools) | |
# Nerd fonts (For some cmd tools to display icons in terminal) | |
wget -P ~/.local/share/fonts https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/FiraCode.zip \ | |
&& cd ~/.local/share/fonts \ | |
&& unzip FiraCode.zip \ | |
&& rm FiraCode.zip \ | |
&& fc-cache -fv | |
# zioxide (smart cd replacement) | |
sudo apt install -y zoxide | |
tee -a ~/.bashrc << ZOXIDE | |
# Zoxide (smart cd replacement) | |
eval "$(zoxide init bash)" | |
ZOXIDE | |
tee -a ~/.zshrc << ZOXIDE | |
# Zoxide (smart cd replacement) | |
eval "$(zoxide init bash)" | |
ZOXIDE | |
# Bat (cat and less alternative for printing to terminal) | |
sudo apt install -y bat | |
# NeoVim vim commandline text editor with plugin system | |
sudo apt install -y neovim | |
# Use SpaceVim vim distribution | |
curl -sLf https://spacevim.org/install.sh | bash | |
# Prettyping (ping alternative with colors and progress bar) | |
sudo apt install -y prettyping | |
# fd (faster find alternative) | |
sudo apt install -y fd-find | |
# ripgrep (faster grep and file content search) | |
sudo apt install -y ripgrep | |
# difftastic and delta (sematic git diff with colors and highlighting) | |
wget https://github.com/Wilfred/difftastic/releases/download/0.61.0/difft-x86_64-unknown-linux-gnu.tar.gz | |
tar -xf difft-x86_64-unknown-linux-gnu.tar.gz | |
mv difft /usr/local/bin/difft | |
sudo chown root:root /usr/local/bin/difft | |
rm difft-x86_64-unknown-linux-gnu.tar.gz | |
sudo apt install -y git-delta | |
# duf (df alternative) | |
sudo apt install -y duf | |
# ncdu (du alternative) | |
sudo apt install -y ncdu | |
# Htop (top alternative) | |
sudo apt install -y htop | |
# eza (ls alternative with colors, git integration, icons and more) | |
wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | sudo gpg --dearmor -o /etc/apt/keyrings/gierens.gpg | |
echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] http://deb.gierens.de stable main" | sudo tee /etc/apt/sources.list.d/gierens.list | |
sudo chmod 644 /etc/apt/keyrings/gierens.gpg /etc/apt/sources.list.d/gierens.list | |
sudo apt update | |
sudo apt install -y eza | |
# tldr (Better help and man pages) | |
sudo apt install -y tldr | |
# jq and yq commandline JSON and Yaml parsers | |
sudo add-apt-repository -y ppa:rmescandon/yq | |
sudo apt install -y jq yq | |
# FZF (Fuzzy search everything) | |
sudo apt install -y fzf | |
tee -a ~/.bashrc << FZF | |
# FZF (Fuzzy substring searching) | |
[ -f /usr/share/doc/fzf/examples/key-bindings.bash ] && source /usr/share/doc/fzf/examples/key-bindings.bash | |
FZF | |
tee -a ~/.zshrc << FZF | |
# FZF (Fuzzy substring searching) | |
[ -f /usr/share/doc/fzf/examples/key-bindings.zsh ] && source /usr/share/doc/fzf/examples/key-bindings.zsh | |
FZF | |
# clipboard | |
sudo apt install -y wl-clipboard | |
# Yazi folder/file preview | |
sudo apt install -y poppler-utils ffmpegthumbnailer imagemagick | |
wget https://github.com/sxyazi/yazi/releases/download/v0.3.3/yazi-x86_64-unknown-linux-gnu.zip | |
unzip yazi-x86_64-unknown-linux-gnu.zip | |
sudo mv yazi-x86_64-unknown-linux-gnu/ya /usr/local/bin/ya | |
sudo mv yazi-x86_64-unknown-linux-gnu/yazi /usr/local/bin/yazi | |
sudo mv yazi-x86_64-unknown-linux-gnu/completions/ya.bash /usr/share/bash-completion/completions/ya | |
sudo mv yazi-x86_64-unknown-linux-gnu/completions/yazi.bash /usr/share/bash-completion/completions/yazi | |
sudo mv yazi-x86_64-unknown-linux-gnu/completions/_ya /usr/share/zsh/vendor-completions/_ya | |
sudo mv yazi-x86_64-unknown-linux-gnu/completions/_yazi /usr/share/zsh/vendor-completions/_yazi | |
sudo chown root:root /usr/local/bin/ya /usr/local/bin/yazi /usr/share/bash-completion/completions/ya /usr/share/bash-completion/completions/yazi /usr/share/zsh/vendor-completions/_ya /usr/share/zsh/vendor-completions/_yazi | |
rm -rf yazi-x86_64-unknown-linux-gnu yazi-x86_64-unknown-linux-gnu.zip | |
tee -a ~/.bashrc << ALIASES | |
# Shell alias commands | |
alias sudo="sudo " | |
alias cd="z" | |
alias vim="nvim" | |
alias less="batcat --pager='less -RF'" | |
alias cat="batcat --paging never" | |
alias ping="prettyping --nolegend" | |
alias preview="yazi" | |
# add support for ctrl+o to open selected file in Helix text editor | |
export FZF_DEFAULT_OPTS="--bind='ctrl-o:execute(hx {})+abort'" | |
export FZF_DEFAULT_COMMAND="fdfind --type file --color=never --hidden --no-ignore" | |
export FZF_ALT_C_COMMAND='fdfind --type directory . --color=never --hidden --no-ignore' | |
alias top="htop" | |
alias find="fdfind" | |
alias du="ncdu -rr -x --exclude .git --exclude node_modules" | |
alias ls="eza --icons" | |
alias df="duf" | |
alias diff="delta" | |
alias grep="rg" | |
alias help="tldr" | |
alias yq="yq -CP" | |
alias pbcopy='wl-copy' | |
alias pbpaste='wl-paste' | |
ALIASES | |
tee -a ~/.zshrc << ALIASES | |
# Shell alias commands | |
alias sudo="sudo " | |
alias cd="z" | |
alias vim="nvim" | |
alias less="batcat --pager='less -RF'" | |
alias cat="batcat --paging never" | |
alias ping="prettyping --nolegend" | |
alias preview="yazi" | |
# add support for ctrl+o to open selected file in Helix text editor | |
export FZF_DEFAULT_OPTS="--bind='ctrl-o:execute(hx {})+abort'" | |
export FZF_DEFAULT_COMMAND="fdfind --type file --color=never --hidden --no-ignore" | |
export FZF_ALT_C_COMMAND='fdfind --type directory . --color=never --hidden --no-ignore' | |
alias top="htop" | |
alias find="fdfind" | |
alias du="ncdu -rr -x --exclude .git --exclude node_modules" | |
alias ls="eza --icons" | |
alias df="duf" | |
alias diff="delta" | |
alias grep="rg" | |
alias help="tldr" | |
alias yq="yq -CP" | |
alias pbcopy='wl-copy' | |
alias pbpaste='wl-paste' | |
ALIASES | |
# setup difftastic | |
git config --global diff.external 'difft' | |
# delta for non-semantic diff | |
git config --global core.pager 'delta' | |
git config --global interactive.diffFilter 'delta --color-only' | |
git config --global delta.navigate 'true' | |
git config --global merge.conflictstyle 'zdiff3' | |
git config --global color.ui true | |
git config --global color.diff-highlight.oldNormal "red bold" | |
git config --global color.diff-highlight.oldHighlight "red bold 52" | |
git config --global color.diff-highlight.newNormal "green bold" | |
git config --global color.diff-highlight.newHighlight "green bold 22" | |
git config --global color.diff.meta "11" | |
git config --global color.diff.frag "magenta bold" | |
git config --global color.diff.commit "yellow bold" | |
git config --global color.diff.old "red bold" | |
git config --global color.diff.new "green bold" | |
git config --global color.diff.whitespace "red reverse" | |
# Optional (git default editor as helix) | |
git config --global core.editor 'hx' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment