zsh cannot execute global npm packages

Today, I installed a npm package globally, no problem here.

Screen Shot 2017-03-11 at 2.01.37 PM.png

But, when I execute the package, there comes an error:

~  yo
zsh: command not found: yo

So, it means that the system doesn’t reallize the path to my package. I confirm by using:

~/W/C/htnmaruko  echo $PATH
/Users/duchoang/.rbenv/shims:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

So that, we need to export the path to where my package is lying in.

Because I installed by -g parameter, so it is lying in global npm. In my case it is being in ~/.npm-global.

Steps:

1. Export your path in ~/.zshrc (in case of using zsh, otherwise using ~/.bashrc) by  print it to your ~/.zshrc or ~/.bashrc file:

~/.n/bin  printf "\nexport PATH=\"\$PATH\":%s\n" ~/.npm-global/bin >> ~/.zshrc

Or just editing with nano:

~  nano /Users/duchoang/.zshrc

2. Now, fire up the changes:

~  . ~/.zshrc

3. And finally, the problem gets solved, the result we have:

Screen Shot 2017-03-11 at 2.03.28 PM

Now we can get back to our work.

What to do if your Rails application cannot connect to Mysql?

When I use my Mac to continue developing my Rails application using Mysql as the database system. It first initialized and developed in Ubuntu.

After bundling tasks, I move to rake db:create to initialize my databases for development and test environment. But the problem comes out:

Mysql2::Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Ok, cd to the

/var/run/mysqld/

Oh, there’s no mysqld.sock there. Ok so there must be error as above error message.

So, I was wondering where is mysqld.sock in my computer? I was installed Mysql through brew and able to connect to Mysql by Mysql Workbench with no problem. So let’s see some variables. Enter to the terminal:

mysqladmin -p variables | grep socket

Provide password, and then you will see something like:

screen-shot-2016-09-24-at-10-16-58-pm

| performance_schema_max_socket_classes                    | 10

| performance_schema_max_socket_instances                  | -1

| socket                                                   | /tmp/mysql.sock|

Wow, there comes in the socket line the mysql.sock file location

We have to connect through it.

After some research, I know that Rails settings the socket in database.yml file.

So, it’s ez now, just replace the new found path.

It’s ok now. I can continue my work.

Fixing rbenv not update ruby system (rbenv version different from ruby -v)

Recently, I faced with the problem of not syncing ruby version with my Mac.

My project requires ruby version >= 2.2.2 but default version is 2.0.0.

I haved installed ruby 2.3.1  on my rbenv (ruby version manager) and set it global, but when i bundle install, there comes some error liked:

activesupport-5.0.0 requires ruby version >= 2.2.2, which is incompatible with the current
version, ruby 2.0.0p648

Even rbenv version shows:

2.3.1 (set by /Users/duchoang/.ruby-version)

I checked back with ruby -v, it shows 2.0.0. Oh shit what happened?

I searched and they said that I have to install ruby-build, ok but after that I reallized that it’s not the cause:

brew install rbenv ruby-build

rbenv rehash

I reallized that I’ve switched to zsh, so instead of ~/.bash_profile I need to rerun the following command to ~/.zshrc:

$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.zshrc
$ source ~/.zshrc

done.

Better color for your Mac Terminal

Run this from terminal:

open ~/.bash_profile

Add these lines to the end:

export TERM="xterm-color" 
export PS1='\[\e[0;33m\]\u\[\e[0m\]@\[\e[0;32m\]\h\[\e[0m\]:\[\e[0;34m\]\w\[\e[0m\]\$ '

Then restart your Terminal to see the changes, now you’re done.

For more customizations, refer to the post: http://osxdaily.com/2012/02/21/add-color-to-the-terminal-in-mac-os-x/

Or, you could try some alternatives:

  • Cathode
  • iTerm2
  • Terminator
  • MacTerm

Create an shortcut to open Terminal in Mac OSX

Launch Automator. Create a document of type “Service”. In the document, add a “Run AppleScript” action. Here’s the AppleScript to paste into the action:

on run {input, parameters}
    tell application "Terminal"
        do script ""
        activate
    end tell
    return input
end run

Set the “Service receives” popup to “no input”. It should look like this overall:

Service definition

Save the document with the name “New Terminal”. Then go to the Automator menu (or the app menu in any running application) and open the Services submenu. You should now see the “New Terminal” service:

New Terminal service menu item

If you click it, Terminal should open a new window.

To assign a keyboard shortcut to it, choose the “Services Preferences…” item from that menu. (Or launch System Preferences, choose the Keyboard pane, then choose the Shortcuts tab, then choose Services from the left-hand list.) Scroll to the bottom of the right-hand list and find the New Terminal service. Click the right end of the New Terminal row and press your preferred keyboard shortcut:

New Terminal shortcut

Now you should be able to press your keyboard shortcut in most circumstances to get a new terminal window.

Copy from: http://stackoverflow.com/a/35954589