The DevOps Phenomenon -- Abstract

The DevOps Phenomenon Continuous Integration and Security  in the Internet Age by Kevin Eberman Abstract This book is about De...

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Thursday, July 2, 2020

Installing and configuring Python on MacOS (Catalina)

Installing Python (latest) on MacOS (Catalina)

New computer... and a new opportunity to setup python. This happens about as often as I update my blog. Things change, so here's what installing python on MacOS looks like circa July 2020. 

Set BASH as default SHELL

First of all... I prefer BASH as my SHELL. In Catalina ZSH is the default. Changing the default shell to BASH is a setting in Terminal:
Terminal--> Preferences --> General * Shells open with: Command (complete path): /bin/bash

Reference:

Suppress annoying ZSH warning 

Apple really would prefer I stop using BASH. When opening a Terminal by default a message tells me that ZSH is now the default shell. That's a quickly tiresome reminder that I really should be using ZSH, and why am I using BASH anyway?--BASH has been deprecated. To make matters worse, the version of BASH installed by default on Catalina is quite old, and ZSH is all up to date. But, I don't want to be deterred, and I don't want to see this warning every time I launch a Terminal window, so, I added this to my ~/.bash_profile (reminder: .bash_profile is used instead of .bashrc on Mac OS X).
export BASH_SILENCE_DEPRECATION_WARNING=1

Set BASH command prompt

Yeah, I have preferences (doesn't everybody?). I set my command prompt to show me which user is active and what directory I'm in. This goes in my .bash_profile:

PS1='\u:\w\$ '

Install brew (MacOS package manager)

There's little life in a laptop you want to use to write code that doesn't have a command line package manager. So... (do this with a user with 'admin' privileges):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" 
Reference:  

Install pyenv, pipenv

Reference: I'm starting this section with the reference, because I want to give a HT to Gioele Barabucci for an amusing nod to how convoluted this has been, and an excellent description of how to setup a modern python environment: 
tl;dr version: Segregate all your project dependencies and versioning by using pyenv and pipenv to manage different environments within a project/directory. This is a really nice way of doing things. It gets all the way around mucking about with the OS provided python installs and versions and your own dependency hell.  Use brew to install these tools. 
brew install pyenv 
brew install pipenv

Installing pyenv creates a .pyenv directory under your home directory where it stores and manages different versions of python so you can have them at your fingertips.

 Configure pyenv

We're getting close now. 

pyenv --list # shows you all the available versions of python that are available. There are a lot!
pyenv install 3.8.3 #install 3.8.3 version of python -- latest
pyenv global 3.8.3 # set 3.8.3 as the default version
pyenv init
This last statement, pyenv init, is the magic that connects your shell to the local versions of python installed and managed by pyenv. Really, all it does is adds the .pyenv directory to your PATH with a symlink to the version of python you want to use. Add this to your .bash_profile to have pyenv manage your python stuff by default.
eval "$(pyenv init -)"
Reference:  
https://realpython.com/intro-to-pyenv/   

 Configure pipenv

 pipenv is the glue between pyenv and your virtual python environments. pipenv install creates a file called Pipfile in your current directory or project where it tracks the python version for this project and any dependent packages you install for THIS project and only THIS project. For example:
pipenv install tweepy 
And as the output helpfully suggests: To activate this project's virtualenv, run:
pipenv shell 
Development environment segregation FTW!  

Install pycharm

Honestly, I might keep using vim for the most part--old habits. I may be an old dog, but I want to learn new tricks, so, installing an IDE. Download the installer here:


EOJ


Thursday, April 7, 2016

TOP 8 || BEST Linux Command Line Tools

Here they are... my eight favorite linux command line tools. 

#8) systat

All systems should have systat installed.  Systat is the easiest way to get basic server performance logging running on a system.  Systat includes the utility sar.  Sar tracks system utilization over time.  There are few things more frustrating then trying to determine what happened over night on your server, and you don’t have any data on the performance of the box because sar is not installed.

#7) rsync

Moving large groups of files around is made a lot easier with rsync.  Rsync computes a unique hash of each file you would like to copy and compares it to your target.  If rsync finds a matched hash, the source and destination files are the same, and file copying is skipped.  Skipping files that have already been copied can really cut down the work effort! Running an rsync in cron is an easy way to keep a backup or replica of data files up to date.

#6) telnet

Telnet is a granddaddy of network tools. Telnet and its server side daemon, telnetd, for many years provided remote console connectivity to servers and network gear.  As it passes traffic in plain text including login information, it has rightly been relegated to the landfill for antiquated technologies.  I haven’t connected to a telnet server in at least a decade. However, the client program is still useful.  Telnet to a well know port enables an interactive session over TCP to many common network programs that pass data in plain text, like HTTP, dns, smtp and even SSH.  SSH doesn’t pass interactive data, but most SSHd servers will tell you the version of SSHd you have connected to.  It’s good for simple tests of network connectivity or for passing protocol commands over the command line.

#5) emacs 

I am a vi user myself, but I admire the heck out of emacs. I recall vividly, back in my WebLogic days in the late 90s, setting up a new developer, Anno Langen. Bob Pasker was walking Anno through the environment. What has stuck in my mind was there 30-minute conversation filled with backslapping and high fives as they compared their emacs macros. For all you emcas people out there, I salute you.

#4) lynx

It may come as a surprise that I have included a text base web browser in a list of must have network tools. But having an actual browser in your console is handy. There are times when it is easier to fire up lynx to smoke test the content of a web page without having to exit the console. Command line tools like wget or curl, don’t always do the job. Sometimes you want an interactive session, not just a single get or post.

#3) mtr

Back in the day, traceroute was a common tool for tracing the path of packets from a source to a destination. It relied on ICMP responses to generate its maps. Because these same useful ICMP responses have been exploited to generate denial of service attacks they have been largely turned off on the Internet. Instead of getting a nice list of hosts between you and your target with useful timing data indicating where in the network there are bottlenecks, you get back a lot of no-replies. MTR to the rescue!  Somewhat similar in look and feel to traceroute, MTR relies on UDP responses to generate its network maps. Once again, we can see where the network bottlenecks are.

#2) nmap

NMAP is a very useful tool for scanning networks and ports. It’s a useful way to uncover information about what system is on the other end. If an nmap reveals port 3369 is open, chances are pretty good you are looking at a windows server. Nmap is also a quick and easy way to scan a range of IP addresses to see what’s on your network and how many IP addresses are in use.

#1) nc

nc may be my favorite of any network tool. What makes nc particularly awesome is its ability to open an ad hoc TCP or UDP port on any available port. This is a great way to test network connectivity between systems and networks during the network build phase, before applications are installed. 

So what do you think? Is there a favorite of yours that is not on the list? Please let me know in the comments.