How to install Dart to be used in the terminal? (command line) - bash

How do you install Dart so the language can be used within the terminal? (For UNIX based systems, such as a Mac)

After installing Dart (currently located at https://www.dartlang.org/), you will need to do some additional work to use dart commands in the terminal (command line), as it needs to be added to the Bash profile PATHs (on a UNIX based system). To do this, run the following handy command to open the .bash_profile file in it’s default location and with the system’s default text editor touch ~/.bash_profile; open ~/.bash_profile.
Next find the directory that Dart was downloaded to and put the path for dart-sdk/bin inside the .bash_profile as apart of the PATH variable. I.e. a line of code should be added to this file that looks something like this (if you’ve put the dart install in the applications folder on a Mac): export PATH=$PATH:/Applications/Dart/dart-sdk/bin.
To get Bash to start using this new profile immediately without restart, enter source ~/.bash_profile in the terminal (command line), then to double check the PATHs have updated, by enter in the command echo $PATH.

1) Install Dart in your environment (if have not yet)
https://www.dartlang.org/tools/sdk#install
2) Add PATH variable for dart/bin
Example for Ubuntu
# add path example
echo 'export PATH="$PATH:/usr/lib/dart/bin"' >> ~/.bashrc
source .bashrc
or it can be .bash_profile instead of .bashrc
3) And now just run your .dart file with the main() method in the terminal and see an output
$ dart path_to_your_file/your_file_with_main.dart

Related

zsh: command not found on MacOS Monterey

I wanted to create a react project and when I executed the command it said zsh: command not found: npx
Then I tried the ls command and it said zsh: command not found: ls.
After setting the export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" command both the ls and npx create-react-app command worked fine and when close the terminal and reopen again, the same command not found error shows.
Is there any permenent fix without setting export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" command
For adding the variables to the path you need to add it to zshrc file for making that variable available locally.
The way you have used will only work until you use it in the same terminal window path only.
To solve the problem, follow these steps:
Goto you home directory
Simultaneously press cmd + shift + (.) Note:the last key is the key of dot
On following step 2, new hidden files will appear in home directory, look for (.zshrc) file and open it using any text editor.
Add your path variable in it, save and then close it.
Example: export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
Open terminal and run the command: "echo $PATH" and see if your added variable is present in the output shown by terminal.
If yes, You are now ready to go to use it from anywhere in terminal now.
This is what worked for me on macOS Monterey,
Although I added the path to ./zshrc and sourced the file, after reopening the terminal the PATH was not exported
I followed these steps to solve this
Created .zprofile with touch .zprofile at the home directory. If the file already exists use that.
Add the required path to this file using vim or nano
eg: export PATH=${PATH}:/Users/Development/HashBaze/flutter/bin
If the above two steps don't work try sourcing both the .zprofile and .zshrc after following the above two steps.
This solution worked for me on macOS Monterey version 12.5

Setting up Flutter in terminal yields a command not found message

I'm trying to setup Flutter on my Mac but when I use the terminal to check the version I keep getting the message "zsh: command not found: flutter"
The steps that I've done to set it up are:
In a terminal window type vim ./zshrc
Paste the export PATH="$PATH:[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin"
code (changing the brackets to the actual file path)
:wq!
Testing the version by typing flutter --version
Is there something I'm missing, or something I'm not doing right?
Your PATH step should likely be:
export PATH="$PATH:[PATH_TO_FLUTTER_GIT_DIRECTORY]/bin"
Note that the directory you want to add to your path is bin, not flutter/bin, relative to the Flutter git directory.
The install instructions for macOS and Linux specify the steps as:
$ git clone https://github.com/flutter/flutter.git
$ export PATH="$PATH:`pwd`/flutter/bin"
Note that the git clone step creates a flutter directory within your current directory, so the path to add is flutter/bin relative to pwd (the current directory).
it can be done with an editor nano or vim which will return a text editor terminal there you can edit path and save,eg
nano .bash_profile
nano .bashrc

Terminal is not working as usual mac after trying to install CakePHP

I was downloading the CakePHP framework for a project. Below the steps:
Installation
1) Install PHP 5.6 from: http://php-osx.liip.ch/
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6
2) add the updated PHP version to our path. So we edit .profile file
nano ~/.profile
Add into the file
export PATH= /usr/local/php5/bin:$PATH
Then hit Control + O to write out the file
Then hit Control + X to save the file
exit
Restart the Terminal
Now the terminal doesn't work as usually. I've tried to understand the shell concept and apply different solutions, but I can't even find the .profile file again.
I obtain errors like:
enter code here-bash: ls: command not found
Anybody can explain me what's wrong and the shell concept to properly understand shell (-bash)?
The problem is this:
export PATH= /usr/local/php5/bin:$PATH
You killed your PATH variable. You need to find a way to edit .profile file, and change that line to:
export PATH=$PATH:/usr/local/php5/bin
You could try editing with the following command (using vim):
/usr/bin/vim /Users/yourname/.profile
Or (using nano):
/usr/bin/nano /Users/yourname/.profile
Or just remove .profile file completely by doing /bin/rm /Users/yourname/.profile. Of course, in any case, you need to restart your terminal once you're done.

How to set up packer PATH on Mac Unix

The documentation of packer says: Packer Setup Documentation
on how to set the PATH : How to permanently set PATH in Unix
And I did add :
export PATH=$PATH:~/packer/
in my ~/.zshrc file
however, when I go to type packer on the terminal first time, the dir changes to be ~/packer and when I type packer again I get :
~ packer
➜ packer packer
zsh: command not found: packer
Does anyone have a better clue on how to set up packer's PATH on a Macintosh Unix system?
In OS X you would typically have any exports set in:
~/.bash_profile
If you already have a .bash_profile setup then it will override .profile. Since you're using zsh you might try putting the export in ~/.zprofile.
Please try adding your edits to the ~/.profile file instead of ~/.bashrc file.
To make the new path stick permanently you need to create a .bash_profile file in your home directory and set the path there.
Open terminal on Mac and write nano .bash_profile.
Create the .bash_profile file with a command line editor called nano,If it is already exists then it will open a text editor containing path.
Add the path you require like:
export PATH="/usr/local/node/bin:$PATH"
Save the file in nano by clicking Ctrl+O and confirming the name of the file as .bash_profile by hitting enter. And the Ctrl+X to exit nano.
Then for checking path is set or not just write echo $PATH in terminal. Your path would be there in it.

Where do I put mxmlc so that I could just type 'mxmlc' in the terminal to compile a swf file?

I'm on a Mac and I'm trying to make a Vim plugin for compiling/running actionscript files.
First, I need to run mxmlc on the command line, but to do that I have to keep on typing the path to it. Where do I place it so that I don't have to retype the path?
You need to modify your "$PATH" environment variable, so that the tool is in that directory. However, if you want to make this very easy... you can download my macosx-environment-setup.tar.bz2 program. If you execute the "install.sh" script using "sudo ./install.sh", it will setup your environment in such a way that if you use "/Library/Flex4SDK" as the location for the Flex4SDK, it will automatically find it, define FLEX_HOME to point to that location, and it will also ensure that the binaries from the Flex4SDK are in your PATH.
Side Note: This is up on the web, because I use it in my Development Environment Setup How-To Guides. If you aren't too keen about running "sudo ./install.sh", you need to choose a location (I am going to assume "/Library/Flex4SDK", so that the tools are located in "/Library/Flex4SDK/bin"), and then you would simply need to edit your "~/.profile" file (using "nano ~/.profile"), adding the following to the very end:
export FLEX_HOME=/Library/Flex4SDK
export PATH="$PATH":"$FLEX_HOME/bin"
Note that these changes occur in your shell... they will not affect programs that are launched by double-clicking them in Finder. In order to affect those programs, you will need to place the environment variables in a file named ~/.MacOSX/environment.plist. See Automatically build ~/.MacOSX/environment.plist for a script that will automatically generate such a file using the current environment variables defined in your shell.
There are a few ways to answer this:
In one of your directories searched
by PATH (see the list with echo
$PATH)
Add a new directory to PATH
(e.g. in your ~/.bashrc
export PATH=$PATH:/path/to/bindir)
Add an
alias to your program (e.g. in your
~/.bashrc alias
mxmic=/path/to/mxmic)
(I'm assuming you're using bash shell, which is usually the case you can check with echo $SHELL)

Resources