Ubuntu

Nesse artigo será exibido detalhadamente os processos feito via terminal para a instalação dos programas

Ubuntu 20.04

After Install

chrome

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

sudo dpkg -i google-chrome-stable_current_amd64.deb

google-chrome --version

flatpak

https://flatpak.org/setup/Ubuntu/

sudo apt install flatpak \
gnome-software-plugin-flatpak

flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

To complete setup, restart your system

flathub

https://flathub.org/

flatpak install flathub com.github.huluti.ImCompressor

flatpak install flathub org.keepassxc.KeePassXC

flatpak install flathub org.gimp.GIMP

flatpak install flathub org.inkscape.Inkscape

flatpak install flathub com.github.micahflee.torbrowser-launcher

flatpak install flathub com.obsproject.Studio

flatpak install flathub org.blender.Blender

flatpak install flathub org.audacityteam.Audacity

flatpak install flathub org.avidemux.Avidemux

snapcraft

https://snapcraft.io/store

snap list
snap version

sudo snap install chromium

sudo snap install google-cloud-sdk --classic

sudo snap install heroku --classic

    heroku -v

sudo snap install riseup-vpn --classic

sudo snap install konversation

sudo snap install ksnip

sudo snap install shotcut --classic

sudo snap install shutter

sudo snap install glade

sudo snap install dbeaver-ce

sudo snap install squirrelsql

sudo snap install code --classic

sudo snap install android-studio --classic

    # https://reactnative.dev/docs/environment-setup

    echo '# Configure the ANDROID_HOME environment variable' >> ~/.bashrc
    echo 'export ANDROID_HOME="$HOME/Android/Sdk"' >> ~/.bashrc
    echo 'export PATH="$PATH:$ANDROID_HOME/emulator"' >> ~/.bashrc
    echo 'export PATH="$PATH:$ANDROID_HOME/tools"' >> ~/.bashrc
    echo 'export PATH="$PATH:$ANDROID_HOME/tools/bin"' >> ~/.bashrc
    echo 'export PATH="$PATH:$ANDROID_HOME/platform-tools"' >> ~/.bashrc
    # echo 'export ANDROID_SDK_ROOT="$ANDROID_HOME"' >> ~/.bashrc
    # echo 'export ANDROID_AVD_HOME="/home/marcio/.android/avd/Pixel_2_API_30.avd"' >> ~/.bashrc

    source ~/.bashrc # load the config into your current shell

    nano ~/.bashrc # check

    echo $ANDROID_HOME

    echo $PATH

    #

sudo snap install intellij-idea-community --classic

sudo snap install netbeans --classic

sudo snap install eclipse --classic

sudo snap install scrcpy

sudo snap install flutter --classic

sudo snap install flutter-gallery

sudo snap install flokk-contacts

DB Visualizer

cd ~/Downloads

wget https://www.dbvis.com/product_download/dbvis-11.0.3/media/dbvis_linux_11_0_3.deb

sudo dpkg -i dbvis_linux_11_0_3.deb

mysql-workbench

cd ~/Downloads

wget https://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-workbench-community_8.0.20-1ubuntu20.04_amd64.deb

sudo dpkg -i mysql-workbench-community_8.0.20-1ubuntu20.04_amd64.deb

# Fix: dpkg: erro ao processar o pacote

sudo apt-get -f install

docker

# https://docs.docker.com/install/linux/docker-ce/ubuntu/

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo apt-key fingerprint 0EBFCD88

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

sudo apt-get update

sudo apt install docker-compose docker-ce docker-ce-cli containerd.io

    docker version
    docker-compose version
    docker-machine version

    docker info
    # Fix: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/images/search?limit=25&term=ubuntu: dial unix /var/run/docker.sock: connect: permission denied
    # By default the docker daemon always runs as the root user, therefore you need to prepend sudo to your Docker command(s).
        groups
    # 1. Create the docker group.
        sudo groupadd docker
    # 2. Add your user to the docker group.
        sudo usermod -aG docker $USER
    # 3. Log out and log back in so that your group membership is re-evaluated.
    # 4. Verify that you can run docker commands without sudo.
        docker run hello-world
    # more ...
        docker info
        docker search ubuntu
        docker container ls

vscode

# Fix: https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc
# FIX: [nodemon] Internal watch failed: ENOSPC: System limit for number of file watchers reached, watch

cat /proc/sys/fs/inotify/max_user_watches

cat /etc/sysctl.conf

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

cat /etc/sysctl.conf

cat /proc/sys/fs/inotify/max_user_watches

# code --list-extensions

    dbaeumer.vscode-eslint
    dsznajder.es7-react-js-snippets
    eamodio.gitlens
    esbenp.prettier-vscode
    felixfbecker.php-intellisense
    foxundermoon.shell-format
    junstyle.php-cs-fixer
    mgmcdermott.vscode-language-babel
    ms-azuretools.vscode-docker
    ms-vscode-remote.vscode-remote-extensionpack
    msjsdiag.vscode-react-native
    yzhang.markdown-all-in-one

# code --install-extension <extension-id>

# OR

# 1 - Launch VS Code
# 2 - Quick Open (Ctrl+P), paste the following command, and press enter.

ext install <extension-id>

echo '# Configure the REACT_EDITOR environment variable' >> ~/.bashrc
echo 'export REACT_EDITOR="code"' >> ~/.bashrc
source ~/.bashrc
nano ~/.bashrc

Java

# Oracle Java 11 e 14

# https://launchpad.net/~linuxuprising/+archive/ubuntu/java

sudo add-apt-repository ppa:linuxuprising/java

sudo apt-get update

# Java 8 a 14

sudo apt install openjdk-8-jdk

# React use java 8

java -version
javac -version
which java
echo $JAVA_HOME
update-alternatives --list java
update-alternatives --display java

sudo update-alternatives --config java # Escolha a devida opção

java -version

ls /usr/lib/jvm
ls /usr/lib/jvm/java-8-openjdk-amd64/bin

cat /etc/environment

echo $(jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));')

echo 'System.out.println(java.lang.System.getProperty("java.home"));' | jshell  -

# adicionar
# export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/"
# export JAVA_HOME="$(jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));')"

sudo nano /etc/environment

source /etc/environment

Homebrew - Package Manager for macOS (or Linux)

# https://brew.sh/

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

    echo '# Configure the Homebrew environment variable' >> ~/.profile
    echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >> ~/.profile

    nano ~/.profile

    # Add Homebrew to your PATH
    eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)

    # - We recommend that you install GCC by running:
    brew install gcc

        # Ainda não executei
        # For compilers to find [email protected] you may need to set:
        export LDFLAGS="-L/home/linuxbrew/.linuxbrew/opt/[email protected]/lib"
        export CPPFLAGS="-I/home/linuxbrew/.linuxbrew/opt/[email protected]/include"

        # For pkg-config to find [email protected] you may need to set:
        export PKG_CONFIG_PATH="/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/pkgconfig"

    # https://facebook.github.io/watchman/docs/install/#installing-on-macos-or-linux-via-homebrew

    brew update
    brew install watchman

        # See: https://docs.brew.sh/Homebrew-and-Python

        # [email protected] is keg-only, which means it was not symlinked into /home/linuxbrew/.linuxbrew, because this is an alternate version of another formula.

        # If you need to have [email protected] first in your PATH run:
        echo 'export PATH="/home/linuxbrew/.linuxbrew/opt/[email protected]/bin:$PATH"' >> ~/.profile

        # For compilers to find [email protected] you may need to set:
        export LDFLAGS="-L/home/linuxbrew/.linuxbrew/opt/[email protected]/lib"
        export CPPFLAGS="-I/home/linuxbrew/.linuxbrew/opt/[email protected]/include"

        # For pkg-config to find [email protected] you may need to set:
        export PKG_CONFIG_PATH="/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/pkgconfig"

    watchman --version

    brew list

PPA (Personal Package Archives)

apt-cache search --names-only 'webp' | grep open

sudo apt install \
    android-tools-adb \
    apt-transport-https \
    build-essential \
    ca-certificates \
    cmake \
    curl \
    direnv \
    ffmpeg \
    gconf2 \
    git \
    git-cola \
    git-lfs \
    gnome-tweaks \
    gnupg-agent \
    gnupg2 \
    graphviz \
    gufw  \
    imagemagick \
    indicator-cpufreq \
    jq \
    lame \
    libavcodec-extra \
    libcanberra-gtk-module \
    links \
    linux-tools-generic \
    lynx \
    meld \
    net-tools \
    nmap \
    openssh-server \
    optipng \
    p7zip-full \
    preload \
    python \
    python3-dev \
    python3-pip \
    ruby-full \
    software-properties-common \
    tlp \
    ubuntu-restricted-extras \
    vlc \
    webp
    zlib1g-dev \

sudo apt install pavucontrol # Fix: hdmi sounds

sudo service ssh start

sudo tlp-stat

which ruby
ruby --version

python3 -V
git --version

# Display live hosts on the network

nmap -sP "$(ip -4 -o route get 1 | cut -d ' ' -f 7)"/24 | grep report | cut -d ' ' -f 5-

ImageMagick

https://github.com/ImageMagick/ImageMagick/issues/396#issuecomment-602026541

update(s)

sudo apt update && sudo apt upgrade

flatpak update

sudo snap refresh

npm update --global

gem update --system

git config

git config --global credential.helper cache
git config --global user.email "[email protected]"
git config --global user.name "USR"
git config --global http.postBuffer 524288000 # FIX: Error: fatal: The remote end hung up unexpectedly, https://confluence.atlassian.com/stashkb/git-push-fails-fatal-the-remote-end-hung-up-unexpectedly-282988530.html
git config --list --global

ssh -T [email protected]

# FIX: [email protected]: Permission denied (publickey)
# Obter a SSH Key
# cat ~/.ssh/id_rsa.pub
# e adicionar em
# https://github.com/settings/keys
# https://bitbucket.org/account/settings/ssh-keys/

git config --local user.name "Mr. mozgbrasil"
git config --local user.email "[email protected]"

Node.js

yarn

# https://classic.yarnpkg.com/en/docs/install#debian-stable

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

sudo apt-get update && sudo apt-get install yarn

node -v
npm -v
yarn -v

yarn config list

yarn config set workspaces-experimental true

NVM - Node Version Manager

# https://www.npmjs.com/
# https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
# https://github.com/nvm-sh/nvm#installing-and-updating
# Global Modules without sudo

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

command -v nvm
nvm ls

nvm install node
nvm install v12.18.0

nvm use node
nvm run node --version

nvm alias default v12.18.1
nvm use default
node -v

nvm current

npm config list
npm list -g --depth 0
ncu --global
npm update --global # --unsafe-perm

npm list --depth 0

npm install -g \
    @prettier/plugin-php \
    concurrently \
    create-react-app \
    expo-cli \
    express-generator \
    lerna \
    nodemon \
    npm-audit-resolver \
    npm-check \
    npm-check-updates \
    pm2 \
    pnpm \
    prettier \
    react-devtools \
    react-native-cli \
    syncpack \
    ts-node \
    pnpm \
    typescript \
    web-ext

npx lib

#

# FIX: [nodemon] Internal watch failed: ENOSPC: System limit for number of file watchers reached, watch

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

#

rubygems

https://rubygems.org/gems

# set up a gem installation directory for your user account
# https://jekyllrb.com/docs/installation/ubuntu/

echo '# Install Ruby Gems to ~/gems' >> ~/.bashrc
echo 'export GEM_HOME="$HOME/gems"' >> ~/.bashrc
echo 'export PATH="$HOME/gems/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

#

gem --version

gem list

gem install \
  bundler \
  jekyll \
  rouge \
  jekyll-watch

bundle -v
jekyll -v

cd ~/dados/projects/mozgbrasil.github.io
bundle install

gem update --system

Jekyll

# Run Jekyll

cd ~/dados/projects/mozgbrasil.github.io
JEKYLL_ENV=production bundle exec jekyll serve --watch --verbose

pypi

https://pypi.org/

which pip
pip3 --help
pip3 --version

pip3 check
pip3 list
pip3 help install

python3 -m pip --version
python3 -m pip check
python3 -m pip list

Dica:

# Após criar uma pasta e compartilhar pelo Nautilus só deve funcionar a autenticação após ser criado o devido usuário no Samba
sudo smbpasswd -a $USER

Devilbox

http://devilbox.org/

Install

mkdir -p /home/marcio/dados/containers_docker

cd ~/dados/containers_docker

git clone https://github.com/cytopia/devilbox.git
cd devilbox
ls

wget https://gist.githubusercontent.com/mozgbrasil/bce7f1318cc3bc762db4319cc474ee59/raw/e2e0a21588b1d1528f577c8dd1b526edde45aeb1/.env

wget docker-compose.yml https://gist.githubusercontent.com/mozgbrasil/bce7f1318cc3bc762db4319cc474ee59/raw/e2e0a21588b1d1528f577c8dd1b526edde45aeb1/docker-compose.yml

docker-compose up

Virtual Hosts

mkdir -p ~/dados/mount/www/localhost/htdocs/

sudo nano /etc/hosts
    127.0.0.1 localhost.loc

cd ~/dados/mount/www/localhost/htdocs/

ln -s /home/marcio/dados/projects

echo "<?php phpinfo(); ?>" > phpinfo.php

cat > .htaccess <<- _EOF_

enable directory browsing

Options +Indexes EOF

Update

cd ~/dados/containers_docker

mkdir tmp
mv devilbox tmp/$(date '+%Y-%m-%d')-devilbox

git clone https://github.com/cytopia/devilbox.git

diff --brief --recursive tmp/$(date '+%Y-%m-%d')-devilbox devilbox

meld tmp/$(date '+%Y-%m-%d')-devilbox devilbox

Commands

cd ~/dados/containers_docker/devilbox
docker-compose down --remove-orphans
docker-compose up

docker --version && docker images && docker images -a && docker images ps && docker ps && docker ps -a && docker network ls

docker stats --all

docker stop $(docker ps -a -q) #stop ALL containers

docker rm -f $(docker ps -a -q) # remove ALL containers

sudo netstat -tulpn # To list open ports use the netstat command

service --status-all
sudo service mysql stop
sudo service apache2 stop
sudo service php7.2-fpm stop



git rev-parse HEAD
id
ls -lah
ls -la data/www
docker-compose up

./shell.sh # Enter the container
cd /shared/httpd/localhost/htdocs/projects/magento2

rm composer.lock
mv composer.json composer-bkp.json
ls
composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento2 -vvv

https://linuxize.com/post/how-to-remove-docker-images-containers-volumes-and-networks/

docker --version && docker images && docker images -a && docker images ps && docker ps && docker ps -a && docker network ls
docker-compose down --remove-orphans
docker-compose stop
docker-compose kill
docker-compose rm -f
docker image prune --force
docker image prune -a --force
docker volume prune --force
docker network prune --force
docker --version && docker images && docker images -a && docker images ps && docker ps && docker ps -a && docker network ls

Fix: tail: recursos esgotados do inotify, tail: inotify não pôde ser usado; revertendo para sondagem (polling)

cat /proc/sys/fs/inotify/max_user_instances # 128
cat /proc/sys/fs/inotify/max_user_watches # 8192
sudo sysctl -w fs.inotify.max_user_instances=12345
sudo sysctl -w fs.inotify.max_user_watches=640123

Sobre o Ubuntu

Para começar a atualização do Ubuntu do sistema, primeiro precisamos atualizar a lista de índice de pacotes. Abra o terminal e digite:

sudo apt update

Podemos instalar a atualização para todos os pacotes de uma só vez: A forma a seguir vai atualizar todas as versões dos pacotes instalados, sem remover pacotes.

sudo apt upgrade

Tudo feito. Seu sistema Ubuntu agora está totalmente atualizado.

Durante a atualização inicial do sistema, alguns dos pacotes podem se tornar obsoletos e, portanto, não são mais necessários. Para remover todos os pacotes desnecessários, execute:

sudo apt autoremove

Para analise do Kernel

dmesg

Para analise da Bios

sudo dmidecode -t bios

UFW ( Uncomplicated Firewall ) é um firewall padrão no Ubuntu 18.04 Bionic Beaver Linux.

Por padrão, o UFW está desativado. Você pode verificar o status do seu firewall executando o seguinte comando:

sudo ufw status

Para habilitar a execução do firewall:

sudo ufw enable

Sincronia para espelhar discos

--archive               archive mode; equals -rlptgoD (no -H,-A,-X)
--update                skip files that are newer on the receiver
--compress              compress file data during the transfer
--delete                delete extraneous files from destination dirs
--verbose               increase verbosity
--progress              show progress during transfer

rsync --archive --update --compress --delete --verbose --progress /home/marcio/Downloads/ /media/marcio/HDD/Downloads/

rsync --archive --update --compress --delete --verbose --progress /home/marcio/dados/ /media/marcio/HDD/dados/


echo "rsync - $(date '+%d/%m/%Y %H:%M:%S')" >> /home/marcio/dados/touch.txt

rsync --archive --update --compress --delete --verbose --progress /home/marcio/dados/ /media/marcio/HDJMicron/2020-05-19-espelho-marcio/dados/

Sincronia entre maquinas locais

rsync --archive --compress --verbose --progress /home/marcio/dados/projects/ [email protected]:/home/marcio/dados/projects/

rsync --archive --compress --verbose --progress /media/marcio/HDJMicron/videos/ [email protected]:/media/marcio/HDD/videos/

rsync -Pav -e "ssh -i $HOME/.ssh/aws-eb" [email protected]:/var/app/current/ /home/marcio/Downloads/070024

Sincronia entre maquinas e dispositivo USB

# Será copiado a devida pasta para o diretório

rsync --archive --compress --verbose --progress ~/dados/projects /media/marcio/usb-ext4/dados/

rsync --archive --compress --verbose --progress ~/dados/projects /media/marcio/Expansion\ Drive/MeusBackups/dados/projects-2019-10-07/

rsync -av --progress ~/Imagens /media/marcio/Expansion\ Drive/MeusBackups/backup_inspiron_7520_01052019/
rsync -av --progress ~/Downloads /media/marcio/Expansion\ Drive/MeusBackups/backup_inspiron_7520_01052019/
rsync -av --progress ~/dados /media/marcio/Expansion\ Drive/MeusBackups/backup_inspiron_7520_01052019/

rsync -av --progress /media/marcio/HDJMicron/2020-04-23/marcio-Inspiron-5548/dados/projects /home/marcio/dados/

Conectar ao SSH “Secure SHell”

Download via SCP “Secure Copy”

scp -r [email protected]:/home/marcio/Imagens/ /home/marcio/Imagens/

Upload via SCP “Secure Copy”

scp -r /home/marcio/Imagens/ [email protected]:/home/marcio/Imagens/

Como criar a SSH Key

ssh-keygen -t rsa

Como obter a SSH Key

cat ~/.ssh/id_rsa.pub

Efetuar login no SSH com chave ppk

https://askubuntu.com/questions/818929/login-ssh-with-ppk-file-on-ubuntu-terminal

sudo apt-get install putty-tools

puttygen yourkey.ppk -O private-openssh -o yourkey.pem

chmod 400 yourkey.pem

ssh -i yourkey.pem [email protected]

Conectar via SFTP pelo nautilus

###Conectar via Samba pelo nautilus

smb://192.168.0.4

Conectar via ssh pelo terminal

Obter a versão do PHP via terminal

php -r \@phpinfo\(\)\; | grep 'PHP Version' -m 1

php -i | grep 'PHP Version' -m 1

Execução comando condicional em linha

sh -c 'if [ "$TRAVIS_PHP_VERSION" = "5.4" ] || [ "$TRAVIS_PHP_VERSION" = "5.5" ]; then echo '0'; else echo '1'; fi;'

How to check if php-fpm is running

php-fpm --test
php-fpm

ps aux | grep php-fpm

netstat -lntp

to see which group the current user belongs to:

groups
groups marcio

to list the group members along with their GIDs.

id $USER

Visualizar erros do servidor

No terminal pode ser o comando para a visualização do log de erro do servidor

tail -f /var/log/apache2/error.log

Monitorando MySQL

Na necessidade de acessar o MySQL Client e ver os processos

mysql -h 'localhost' -u root -p

show processlist;

ou melhor ainda

mysqladmin -u root -p -i 1 processlist

mysql config

mysql -h '127.0.0.1' -P '3306' -u 'root' -p'12345' -e "SHOW GLOBAL VARIABLES LIKE 'innodb_buffer_pool_size';"

mysql --help

sudo echo "innodb_buffer_pool_size = 8M" >> /etc/mysql/mysql.conf.d/mysqld.cnf

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

cat /etc/mysql/mysql.conf.d/mysqld.cnf

sudo systemctl status mysql
sudo systemctl restart mysql

mysql -h '127.0.0.1' -P '3306' -u 'root' -p'12345' -e "SHOW GLOBAL VARIABLES LIKE 'innodb_buffer_pool_size';"

Recursively fix bad file permissions

# A common suggestion is to use which means:

# 755 for directories: full control for the user, and everyone else can traverse directories.
# 644 for files: read-write permissions for the user, and read-only for everyone else.

find /home/marcio/dados/projects/ -not \( -wholename "*.git*" -prune \) -type f -exec echo [email protected] {} \;

find /home/marcio/dados/projects/ -not \( -wholename "*.git*" -prune \) -type d -exec echo [email protected] {} \;


find /home/marcio/dados/projects/ -not \( -wholename "*.git*" -prune \) -type f -exec chmod 644 {} \;

find /home/marcio/dados/projects/ -not \( -wholename "*.git*" -prune \) -type d -exec chmod 755 {} \;